的Bonjour,
我尝试重定向网站的网址 示例:
www.exemple.net/?p=2
至
www.exemple.net/index-2.html
www.exemple.net/?p=35 至 www.exemple.net/index-35.html 等...
所以我将这些行添加到我的.htacess:
RewriteCond %{QUERY_STRING} ^(?)p=(.*)$ [NC]
RewriteRule .* /index-%1.html [L,R=301]
但我已重定向到http://www.exemple.net/index-2.html?p=2
我的.htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^exemple.net$
RewriteRule ^(.*) http://www.exemple.net/$1 [QSA,L,R=301]
RewriteCond %{QUERY_STRING} ^(?)p=(.*)$ [NC]
RewriteRule .* /index-%1.html [L,R=301]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
你能帮我吗?
答案 0 :(得分:0)
您需要在目的地末尾添加一个问号以放弃查询字符串:
RewriteRule .* /index-%1.html? [L,R=301]
或者,使用QSD
标志:
RewriteRule .* /index-%1.html [QSD,L,R=301]
答案 1 :(得分:0)
尝试:
#Redirecting /?p=2
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/\?p=([^&\s]+) [NC]
RewriteRule ^ /index-%1.html? [NE,NC,R,L]
#Redirecting /transfer?p=2
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/transfer\?p=([^&\s]+) [NC]
RewriteRule ^ /transfer-%1.html? [NE,NC,R,L]
#Redirecting /blog?p=2
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/blog\?p=([^&\s]+) [NC]
RewriteRule ^ /blog-%1.html? [NE,NC,R,L]