重定向和映射使用htaccess的同一页 [英] redirection and mapping for same page using htaccess
本文介绍了重定向和映射使用htaccess的同一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
重定向和映射使用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} ^视图=([^&放大器;] *)及P =([0-9] +)及(。*)/ $
重写规则^见解/(。+?)\。HTML $见解/ $ 1 /%1 /%2 - %3.html? [R = 301,L]
映射
(*)(。*) 重写规则^见解/ / /([0-9] +) - \ HTML $ /insights/$1.html(*)。?鉴于= $ 2及P = $ 3及/ $ 4 L,QSA,NC]
解决方案
这应该工作,你想做什么:
选项+了FollowSymLinks -MultiViews
RewriteEngine叙述上
的RewriteBase /
#重定向/insights/anything.html?view=anything&p=anything&/anything
#要/insights/anything/anything-anything.html
?的RewriteCond%{THE_REQUEST} ^ [AZ] {3,} \ S / +(见解)/([^] +)\ HTML \视图=([^&放大器; \ S] +)及P =( [^&安培; \ S〕+)及/([^&安培; \ S〕+)[NC]
重写规则^ /%1/%2/%3/%4-%5.html? [R = 302,L]
#内部前进/insights/anything/anything-anything.html
#要/insights/anything.html?view=anything&p=anything&/anything
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!-f
重写规则^([^ /] +)/([^ /] +)/([^ /] +)/([^ - ] +) - ([^] +)的html $ /$1/$2.html ?鉴于= $ 3安培; P = $ 4和/ $ 5 L]
修改 R = 302
到 R = 301
您确认该规则后,才正努力避免你的浏览器从缓存错误的重定向。
redirection and mapping for same page using htaccess not working
Ex . www.xyz.com?view=aa¶m=bb
-- redirect it to www.xyz.com/aa/bb
Then map www.xyz.com/aa/bb
to
www.xyz.com?view=aa¶m=bb
below is the rules.
redirection
RewriteCond %{QUERY_STRING} ^view=([^&]*)&p=([0-9]+)&/(.*)$
RewriteRule ^insights/(.+?)\.html$ insights/$1/%1/%2-%3.html? [R=301,L]
mapping
RewriteRule ^insights/(.*)/(.*)/([0-9]+)-(.*)\.html$ /insights/$1.html?view=$2&p=$3&/$4 [L,QSA,NC]
解决方案
This should work to what you're trying to do:
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]
Change R=302
to R=301
only after you have confirmed the rule is working to avoid your browser from caching wrong redirects.
这篇关于重定向和映射使用htaccess的同一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文