1

我有一些需要重定向的链接,例如:

/pass-help.php?action=1&email=test@test.com to /about/help
or
/contests/contest-a?testa=1&testb=1 /user/index/contest

我需要一种方法来在上面的链接中找到 theaction或 the email,因为它们可以是任何东西。

也许像 /pass-help.php?action= (\?.+)&email=(\?.+)到 /about/help

但我不确定如何编写查询字符串。

有任何想法吗?

如果是这样,请解释一下,以便我了解发生了什么。

谢谢

4

1 回答 1

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 的情况下,最后会有一个 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]
于 2012-09-26T21:48:03.033 回答