我想通过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