如果查詢字符串並不重要,你可以不理會他們:
通過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的情況下,最後會有一個stub ?
。這是爲了擺脫查詢字符串所需要的。
如果查詢字符串需要有一定的PARAM的名字,但你不關心的值:
用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]
如果查詢字符串需要有一些PARAM名確切的一些價值:
RewriteCond %{QUERY_STRING} (^|&)action=1
RewriteCond %{QUERY)STRING{ (^|&)[email protected]
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]