使用htaccess无法正常工作的同一页面的重定向和映射
前。 www.xyz.com?view=aa¶m=bb
- 将其重定向到www.xyz.com/aa/bb
然后将www.xyz.com/aa/bb
映射到
www.xyz.com?view=aa¶m=bb
以下是规则。
RewriteCond %{QUERY_STRING} ^view=([^&]*)&p=([0-9]+)&/(.*)$
RewriteRule ^insights/(.+?)\.html$ insights/$1/%1/%2-%3.html? [R=301,L]
RewriteRule ^insights/(.*)/(.*)/([0-9]+)-(.*)\.html$ /insights/$1.html?view=$2&p=$3&/$4 [L,QSA,NC]
答案 0 :(得分:0)
将这两条规则放在.htaccess的顶部:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+\?view=([^&]+)¶m=([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /?view=$1¶m=$2 [L,QSA]
答案 1 :(得分:0)
这应该适用于你想要做的事情:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# Redirect /insights/anything.html?view=anything&p=anything&/anything
# To /insights/anything/anything-anything.html
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(insights)/([^.]+)\.html\?view=([^&\s]+)&p=([^&\s]+)&/([^&\s]+) [NC]
RewriteRule ^ /%1/%2/%3/%4-%5.html? [R=302,L]
# Internally forward /insights/anything/anything-anything.html
# To /insights/anything.html?view=anything&p=anything&/anything
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^-]+)-([^.]+).html$ /$1/$2.html?view=$3&p=$4&/$5 [L]
只有在您确认规则有效以避免浏览器缓存错误的重定向后,才能将R=302
更改为R=301
。