我想通過htaccess使用mod重寫PHP網站。使用Mod Rewrite來更改URL結構
URL結構如下:
example.com/ex.php?ez=DF004AE
它必須成爲:
example.com/ex/DF004AE.htm
什麼是正確的腳本添加到我的.htaccess才能做到這一點?
我想通過htaccess使用mod重寫PHP網站。使用Mod Rewrite來更改URL結構
URL結構如下:
example.com/ex.php?ez=DF004AE
它必須成爲:
example.com/ex/DF004AE.htm
什麼是正確的腳本添加到我的.htaccess才能做到這一點?
RewriteEngine On
RewriteRule ^ex/([^/]*)\.html$ /ex.php?ez=$1 [R=301,NE,L]
如果您不希望地址欄反映此更改,請刪除R = 301。 NE參數用於確保請求不會被轉義。
您可以使用以下規則:
RewriteEngine on
# Redirect from "/ex.php?ez=foobar" to "/ex/foobar.htm"
RewriteCond %{THE_REQUEST} /ex\.php\?ez=([^\s]+) [NC]
RewriteRule^/ex/%1.htm? [L,R]
####################
# internally map "/ex/foobar.htm" to "/ex.php?ez=foobar"
RewriteRule ^ex/([^.]+)\.htm$ /ex.php?ez=$1 [NC,L]
這將/ex.php?ez=foobar
轉化爲/ex/foobar.htm
。
你嘗試過什麼嗎? – apokryfos
新的網址是否存在? – starkeen
不,它只是一個漂亮的SEO鏈接 – marya