[英]rewriting URL to all lowercase
我的.htaccess中有此重寫規則
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/.]+)/?(.*)$ /$1.php/$2 [QSA,L]
RewriteRule ^api/([a-z]+)/([a-z]+) /api/$1_$2.php
如何修改此設置以將URL中的所有內容更改為小寫?
即:
www.mysite.com/ThisURL/SHOULD/be_all_lowercse
應該
www.mysite.com/thisurl/should/be_all_lowercase
本文介紹了如何執行此操作:
RewriteEngine On
RewriteMap lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
定義一個int
類型(內部)的RewriteMap,引用tolower
函數,並在您要進行小寫的地方調用它:
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}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.