.htaccess 如何使用查询字符串执行htaccess 301重定向?

.htaccess 如何使用查询字符串执行htaccess 301重定向?,.htaccess,mod-rewrite,redirect,query-string,http-status-code-301,.htaccess,Mod Rewrite,Redirect,Query String,Http Status Code 301,我有一些需要重定向的链接,如: /pass-help.php?action=1&email=test@test.com to /about/help or /contests/contest-a?testa=1&testb=1 /user/index/contest 我需要一种方法来找到上述链接的行动或电子邮件,因为他们可以是任何东西 可能类似于/pass help.php?action=\?。+&email=\?。+to/about/help 但是我不知道如何编写查询字符串

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

/pass-help.php?action=1&email=test@test.com to /about/help
or
/contests/contest-a?testa=1&testb=1 /user/index/contest
我需要一种方法来找到上述链接的行动或电子邮件,因为他们可以是任何东西

可能类似于/pass help.php?action=\?。+&email=\?。+to/about/help

但是我不知道如何编写查询字符串

有什么想法吗

如果是这样的话,请解释一下,以便我能理解发生了什么


谢谢

如果查询字符串不重要,您可以忽略它们:

通过mod_别名:

Redirect 301 /pass-help.php /about/help?
Redirect 301 /contests/contest-a /user/index/contest?
通过mod_重写:

RewriteRule ^/?pass-help\.php$ /about/help? [L,R=301]
RewriteRule ^/?contests/contest-a /user/index/contest? [L,R=301]
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]
请注意,在mod_别名的情况下,将出现stary?最后。为了摆脱查询字符串,需要这样做

如果查询字符串需要一些参数名,但您不关心这些值:

通过mod_重写:

RewriteRule ^/?pass-help\.php$ /about/help? [L,R=301]
RewriteRule ^/?contests/contest-a /user/index/contest? [L,R=301]
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]