1

在 htaccess 文件中,以下工作

redirect 302 /old.php http://somesite.com/new.php

但以下失败

redirect 302 /old.php?this=that http://somesite.com/new.php

我认为这是因为第二个版本包含一个查询字符串。我们如何重定向这样的 URL?

请注意,目标 URL 格式不同,因此它不能成为自动规则,因此我需要编写用户将被重定向到的自定义 URL。

我在这里的回复中发现了一个类似的问题,但建议的解决方案不起作用:

.htaccess 无法重定向 url

谢谢

4

1 回答 1

1

您可以将此规则用作旧域的站点根目录 .htaccess 中的最顶层规则:

RewriteEngine On

RewriteCond %{QUERY_STRING} (?:^|&)this=that(?:&|$) [NC]
RewriteRule ^old\.php$ http://somesite.com/new.php? [R=301,L]
于 2020-06-17T07:26:03.710 回答