mod_rewrite 将大写路径重写成小写路径
技术交流
@ 2010年08月13日
一个同事今天提到的一个问题,将凡是包含大写字母的路径都通过 301 HTTP 头重定向到小写字母的路径,通过 Apache 的 mod_rewrite 可以达到目的,这里使用了 RewriteMap 的内部映射函数 int:tolower,请查看 http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/mod_rewrite.html#RewriteMap。
RewriteBase /
RewriteMap lowercase int:tolower
RewriteRule .*[A-Z].* ${lowercase:$0} [L,R=301]
貌似 RewriteMap 不能写到 .htaccess 内,会提示以下错误,只能放到配置文件了,如果有更好的解决方案,请联系我啦 :D
.htaccess: RewriteMap not allowed here