转换为小写的的mod_rewrite规则 [英] Convert to lowercase in a mod_rewrite rule
问题描述
我想喜欢server.com/foo网址是区分大小写。
但实际上server.com/foo被mod_rewrite'd到server.com/somedir/foo
I would like URLs like server.com/foo to be case-insensitive. But server.com/foo actually gets mod_rewrite'd to server.com/somedir/foo
(假定在somedir所有的文件都是小写)。
(Assume that all the files in "somedir" are lower case.)
所以现在的问题是,如何完成像下面这样的mod_rewrite的:
So the question is, how to accomplish a mod_rewrite like the following:
RewriteRule ^([^/]+)/?$ somedir/convert_to_lowercase($1)
PS:这里有一个方便的mod_rewrite作弊表 - http://dreev.es/modrewrite - 尽管它不能回答这个问题特定问题。
PS: Here's a handy mod_rewrite cheat sheet -- http://dreev.es/modrewrite -- though it fails to answer this particular question.
PPS:感谢
蜂
和
伊格纳西奥
所有与此帮助。
此外,这里有一个相关的问题:
<一href=\"http://stackoverflow.com/questions/703709/rewritemap-activation\">http://stackoverflow.com/questions/703709/rewritemap-activation
推荐答案
首先,将在&LT以下行;虚拟主机&GT;你的.conf文件中的
部分。
(对我来说住在 /etc/httpd/vhosts.d/00foo.conf
)
RewriteMap lc int:tolower
您可以用任何你想要的名称替换 LC
。
然后重新启动Apache,你可以用做须藤服务的httpd重新启动
。
You can replace lc
with any name you want.
Then restart apache, which you can do with sudo service httpd restart
.
最后,在你的.htaccess文件添加此:
Finally, add this in your .htaccess file:
RewriteRule ^/(.*)$ /${lc:$1}
这篇关于转换为小写的的mod_rewrite规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!