【问题标题】:Redirect any directory if it has a specific query string如果具有特定查询字符串,则重定向任何目录
【发布时间】:2018-07-01 18:46:49
【问题描述】:

我正在尝试将具有特定查询字符串的所有页面重定向到另一个页面。 很多页面都有这个查询字符串,但是 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】:

    您可以将此重定向规则用作站点根目录中的顶级规则

    RewriteEngine On
    
    RewriteCond %{QUERY_STRING} ^redirectme=1$ [NC]
    RewriteRule ^ /newpage? [R=301,L]
    
    # remaining rules below this line
    

    【讨论】:

    • 谢谢!我现在意识到这也是定位!
    猜你喜欢
    • 1970-01-01
    • 2014-09-09
    • 2015-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多