我有一個完整的網站建立在查詢字符串的鏈接方案上(即?page = about或?page = individual & i = johndoe)。當然,回想起來,我們決定採用不同的(美化)方案,以便更加適合搜索引擎優化(即/ about/or/individual/johndoe /)。如何美麗的查詢字符串的網址
有沒有辦法在Apache .htaccess文件上使用mod_rewrite來完成這種改變,而不必更改站點範圍內的所有鏈接?例如,如果你點擊一個鏈接到?page =關於它會永久地將你重定向到/ about /。
我試過的代碼將成功顯示/ about/as?page = about,但是,沒有涉及重定向。說實話,我從來沒有在mod_rewrite上做過任何工作(這有點嚇人),所以我覺得我會走錯方向。儘管如此,這是迄今爲止我一直在使用的代碼:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_]+)$ /$1/ [R]
RewriteRule ^([a-zA-Z0-9_]+)/$ /index.php?page=$1
RewriteRule ^([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)$ /$1/$2/ [R]
RewriteRule ^([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/$ /index.php?page=$1&i=$2
RewriteRule ^([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/$ /index.php?page=$1&id=$2
RewriteRule ^([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/$ /index.php?page=$1&bctid=$2
RewriteRule ^([a-zA-Z0-9_]+)/([a-zA-Z0-9_]+)/$ /index.php?page=$1&bclid=$2
有什麼想法?我非常感謝任何幫助。
有匹配相同的模式是行不通的多個重寫規則,是與案件在你的例子中最底層的4個重寫規則,因爲只有這些規則中的第一個會被apache選中。此外,你應該使用301重定向永久重定向。 –