htaccess redirect URL with parameter 当存在特殊参数时

htaccess redirect URL with parameter when a special parameter exists

我希望得到以下任务的帮助:

我只想在调用 index.php 并且指定特殊参数时使用 htaccess 重定向域。 假设我有以下 URL

https://www.my-domain.com/index.php?action=status-check&licence=80586f63&product=RFDE&domain=domain.tld

当这个 URL 被调用并且参数 action 存在时,它应该被重定向到

https://www.other-domain.com/index.php?action=status-check&licence=80586f63&product=RFDE&domain=domain.tld

如果只是

https://www.my-domain.com/index.php?parm=4711

https://www.my-domain.com/index.php

被调用或在此域中调用任何其他 URL 但没有参数 action,应该不会发生任何事情。

谁能帮我找到合适的条件和规则?!

谢谢!

您可以在根 .htaccess 文件的顶部执行类似以下操作:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)my-domain\.com
RewriteCond %{QUERY_STRING} (^|&)action=
RewriteRule ^index\.php$ https://www.other-domain.com/[=10=] [R=302,L]

action URL 参数存在于查询字符串中的任何位置时,这会重定向 www.my-domain.com/index.php(有或没有 www 子域)(尽管您的示例仅在 start 查询字符串?)。 URL-路径和查询字符串都保留在重定向到 www.other-domain.com 中。 action URL 参数可以有任何值。

[=16=] 反向引用包含 RewriteRule 模式 的整个匹配项,即。 index.php 成功。默认情况下会传递原始查询字符串 - 您无需在此处执行任何额外操作即可重定向到 same 查询字符串。

如果 www.other-domain.com 在不同的服务器上,并且在原始主机上没有其他域可能发生冲突,那么您也许可以删除检查 HTTP_HOST 服务器变量的第一个条件。