我有这个网址:
www.site.ru/page.php?article=anyname
我想看到这个网址:
www.site.ru/anyname
我的重写规则是:
RewriteRule /page.php?article=(.*)$ /$1 [R=301,L]
但它不起作用,为什么?
答案 0 :(得分:1)
将此代码放在DOCUMENT_ROOT/.htaccess
文件中:
RewriteEngine On
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+page\.php\?article=([^\s&]+) [NC]
RewriteRule ^ /%1? [R=302,L,NE]
# internal forward from pretty URL to actual one
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ page.php?article=$1 [L,QSA]