在 mod_rewrite 规则中转换为小写 [英] Convert to lowercase in a mod_rewrite rule

查看:24
本文介绍了在 mod_rewrite 规则中转换为小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望像 server.com/foo 这样的 URL 不区分大小写.但是 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:感谢蜜蜂伊格纳西奥在这方面的所有帮助.另外,这里有一个相关的问题:RewriteMap 激活

PPS: Thanks to Bee and Ignacio for all the help with this. Also, here's a related question: RewriteMap activation

推荐答案

首先,将以下行放入 .conf 文件的 部分.(对于我住在 /etc/httpd/vhosts.d/00foo.conf.)

First, put the following line in the <VirtualHost> section of your .conf file. (For me that lives at /etc/httpd/vhosts.d/00foo.conf.)

RewriteMap lc int:tolower 

您可以将 lc 替换为您想要的任何名称.然后重启apache,你可以用sudo service httpd restart.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆