作者 : Bun Wong
日期 : 2010年08月13日
标签 : Apache
浏览 : 1123 次
评论 : 0 个
http://www.hdwong.com/article/apache-rewrite-url-lowercase.html

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

评论 (0)

还没有评论

* 昵称:

* 评论:

* 验证码: (请输入下图的 4 位数字)

Captcha看不请, 换一张

© 2011 Bun Wong

本博客基于 Bun PHP Framework 构建 • 粤ICP备07036370号