如果任何目录具有特定的查询字符串,则重定向

问题描述 投票:2回答:1

我正在尝试将具有特定查询字符串的所有页面重定向到另一个页面。这么多页面有这个查询字符串,但URI是不同的。我想捕获任何URI,如果它有这个查询字符串来重定向它,但我正在做的没有工作。

所以要明确一点: http://example.com/?redirectme=1 将重定向到 http://example.com/newpage 还有: http://example.com/randompage/rtandomsirectory?redirectme=1 也会重定向到 http://example.com/newpage

我相信我必须有2-3行才能在htaccess中执行此操作,但它无效。这是一个wordpress网站,如果这应该有所作为。

这是我尝试过的:

RewriteCond %{REQUEST_URI} ^/(.+)
RewriteCond %{QUERY_STRING} ^redirectme=1$
RewriteRule ^/?$ http://example.com/? [R=301,L]

RewriteCond %{REQUEST_URI} ^/(.+)
RewriteCond %{QUERY_STRING} ^redirectme=1$
RewriteRule (.*) http://example.com/? [R=301,L]

不同的变化:

RewriteCond %{REQUEST_URI} (.+)
RewriteCond %{QUERY_STRING} ^redirectme=1$
RewriteRule (.*) http://example.com/? [R=301,L]

并为第一行:

RewriteCond %{REQUEST_URI} (.*)

等等....

这里有专家吗?

谢谢

wordpress apache .htaccess
1个回答
3
投票

您可以将此重定向规则用作站点根目录中的最高规则:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^redirectme=1$ [NC]
RewriteRule ^ /newpage? [R=301,L]

# remaining rules below this line
© www.soinside.com 2019 - 2024. All rights reserved.