将URL重写为全部小写

时间:2012-05-05 05:00:52

标签: php regex .htaccess

我的.htaccess

中有这个重写规则
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/.]+)/?(.*)$ /$1.php/$2 [QSA,L]
RewriteRule ^api/([a-z]+)/([a-z]+) /api/$1_$2.php

如何修改此项以将网址中的所有内容更改为小写?

即。这样:

www.mysite.com/ThisURL/SHOULD/be_all_lowercse

应该是

www.mysite.com/thisurl/should/be_all_lowercase

2 个答案:

答案 0 :(得分:2)

article描述了如何执行此操作:

RewriteEngine On
RewriteMap  lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]

答案 1 :(得分:1)

定义一个引用int函数的tolower(内部)类型的RewriteMap,并将其调用到您想要进行小写的位置:

RewriteMap  lc int:tolower
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/.]+)/?(.*)$ /${lc:$1}.php/${lc:$2} [QSA,L]
RewriteRule ^api/([a-z]+)/([a-z]+) /api/${lc:$1}_${lc:$2}.php}