如果查询字符串无关紧要,您可以忽略它们:
通过 mod_alias:
Redirect 301 /pass-help.php /about/help?
Redirect 301 /contests/contest-a /user/index/contest?
通过 mod_rewrite:
RewriteRule ^/?pass-help\.php$ /about/help? [L,R=301]
RewriteRule ^/?contests/contest-a /user/index/contest? [L,R=301]
请注意,在 mod_alias 的情况下,最后会有一个 stary ?
。为了摆脱查询字符串,这是必需的。
如果查询字符串需要一些参数名称,但您不关心这些值:
通过 mod_rewrite:
RewriteCond %{QUERY_STRING} (^|&)action=
RewriteCond %{QUERY)STRING{ (^|&)email=
RewriteRule ^/?pass-help\.php$ /about/help? [L,R=301]
RewriteCond %{QUERY_STRING} (^|&)testa=
RewriteCond %{QUERY_STRING} (^|&)testb=
RewriteRule ^/?contests/contest-a /user/index/contest? [L,R=301]
如果查询字符串需要一些参数名称,并带有一些值:
RewriteCond %{QUERY_STRING} (^|&)action=1
RewriteCond %{QUERY)STRING{ (^|&)email=test@test.com
RewriteRule ^/?pass-help\.php$ /about/help? [L,R=301]
RewriteCond %{QUERY_STRING} (^|&)testa=1
RewriteCond %{QUERY_STRING} (^|&)testb=1
RewriteRule ^/?contests/contest-a /user/index/contest? [L,R=301]