我想用.htaccess文件的.htaccess自定義參數重定向
舊的URL重定向以下鏈接:localhost/info.php?butter_cake-cid111.html
要
新的URL:localhost/butter_cake/cid/111.html
在此先感謝。
我想用.htaccess文件的.htaccess自定義參數重定向
舊的URL重定向以下鏈接:localhost/info.php?butter_cake-cid111.html
要
新的URL:localhost/butter_cake/cid/111.html
在此先感謝。
您可以在DOCUMENT_ROOT/.htaccess
文件中使用這樣的規則:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^([^-]+)-([a-z]+)(\d+\.html)$ [NC]
RewriteRule ^info\.php$ /%1/%2/%3? [L,NC,R=302]
RewriteCond
是匹配和捕獲所有要在目標URL後使用的值。 ?
最後會剝離掉以前的查詢字符串。
是否只有單個URL重定向或您有更多?如果是,則提供示例。 – anubhava
1000多舊的URL:本地主機/ info.php的butter_milk-cid112.html 要 新的URL:本地主機/ butter_milk/CID/112.html,還有更多像這樣的 – Ajinkya