我有一些我需要重定向的链接,例如:
/pass-help.php?action=1&email=test@test.com to /about/help
or
/contests/contest-a?testa=1&testb=1 /user/index/contest
我需要一种方法来查找上面链接中的action
或email
,因为它们可以是任何内容。
可能类似/pass-help.php?action=(\?.+)
&email=(\?.+)
/ about / help
但我不确定如何编写查询字符串。
任何想法?
如果是这样,请解释一下,以便我能理解发生了什么。感谢
答案 0 :(得分:0)
如果查询字符串无关紧要,您可以忽略它们:
通过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情况下,最后会有一个?
。为了摆脱查询字符串,这是必需的。
如果查询字符串需要有一些参数名称,但您不关心值:
通过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]