我正在尝试按如下方式完成一些重定向:
#Basic Rule Set
RewriteRule ^/path$ http://newhost.com/Page?pagename=form1000 [R=301]
RewriteRule ^/path/index.html$ http://newhost.com/Page?pagename=form1000 [R=301]
哪个工作正常。
但是,在源和目标中使用查询字符串重定向会将我返回到上面的目标网址。例如,
# Advanced Rule Set
RewriteRule ^/path/index.html?var=foo$ http://newhost.com/Page?pagename=form1000?id=hello [R=301]
RewriteRule ^/path/index.html?var=bar$ http://newhost.com/Page?pagename=form1000?id=byebye [R=301]
RewriteRule ^/path/index.html?var=xyz$ http://newhost.com/Page?pagename=form1000?id=world [R=301]
全部重定向到http://newhost.com/Page?pagename=form1000
。
我在上述三条规则之前尝试了RewriteCond %{QUERY_STRING} ^var=(.*)$ [NC]
和RewriteCond %{REQUEST_URI} ^/path/index.html [NC]
,但我仍然被重定向到http://newhost.com/Page?pagename=form1000
。我已经转换了基本规则集和高级规则集的顺序,并且都重定向到http://newhost.com/Page?pagename=form1000
。
关于如何让这些规则集生效的任何想法? CentOS 6.x,Apache 2.2。
答案 0 :(得分:1)
您可以尝试这样做:
# Advanced Rule Set
RewriteCond %{QUERY_STRING} var=foo [NC]
RewriteRule ^path/index.html/? http://newhost.com/Page?pagename=form1000?id=hello [R=301,L,NC]
RewriteCond %{QUERY_STRING} var=bar [NC]
RewriteRule ^path/index.html/? http://newhost.com/Page?pagename=form1000?id=byebye [R=301,L,NC]
RewriteCond %{QUERY_STRING} var=xyz [NC]
RewriteRule ^path/index.html/? http://newhost.com/Page?pagename=form1000?id=world [R=301,L,NC]