在 mod_rewrite 规则中转换为小写
我希望像 server.com/foo 这样的 URL 不区分大小写。 但是 server.com/foo 实际上将 mod_rewrite'd 到 server.com/somedir/foo
(假设“somedir”中的所有文件都是小写的。)
所以问题是,如何完成如下所示的 mod_rewrite:
RewriteRule ^([^/]+)/?$ somedir/convert_to_lowercase($1)
PS:这是一个方便的 mod_rewrite 备忘单 - http://dreev.es/modrewrite - 尽管它无法回答这个问题特别的问题。
PP:感谢 蜜蜂 和 伊格纳西奥 感谢所有对此的帮助。 另外,这是一个相关问题: RewriteMap 激活
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
(Assume that all the files in "somedir" are lower case.)
So the question is, how to accomplish a mod_rewrite like the following:
RewriteRule ^([^/]+)/?$ somedir/convert_to_lowercase($1)
PS: Here's a handy mod_rewrite cheat sheet -- http://dreev.es/modrewrite -- though it fails to answer this particular question.
PPS: Thanks to
Bee
and
Ignacio
for all the help with this.
Also, here's a related question:
RewriteMap activation
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,将以下行放入 .conf 文件的
部分。(对于我来说,它位于
/etc/httpd/vhosts.d/00foo.conf
。)您可以将
lc
替换为您想要的任何名称。然后重新启动 apache,您可以使用
sudo service httpd restart
来完成此操作。最后,将其添加到您的 .htaccess 文件中:
First, put the following line in the
<VirtualHost>
section of your .conf file.(For me that lives at
/etc/httpd/vhosts.d/00foo.conf
.)You can replace
lc
with any name you want.Then restart apache, which you can do with
sudo service httpd restart
.Finally, add this in your .htaccess file:
出于 SEO 目的,我会将其设为 301 重定向,而不是 URL 重写:
I would make it a 301 redirect, NOT a URL rewrite, for SEO purposes: