【问题标题】:Remove the query parameters that are appended while redirection移除重定向时附加的查询参数
【发布时间】:2018-02-16 18:09:55
【问题描述】:

我有 WordPress .htaccess 文件,这是它的外观。

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# the following three lines will work for all subdomains
RewriteCond %{HTTP_HOST} !^example\.net$ [NC]
RewriteCond %{HTTP_HOST} !^www\.example\.net$ [NC]
RewriteRule . "http://www.example.net/" [R=301,L]

# the following two lines will redirect non-www to www version of the domain
RewriteCond %{HTTP_HOST} ^example\.net
RewriteRule ^(.*)$ "http://www.example.net/$1" [R=301,L]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# Wordfence WAF

<Files ".user.ini">
<IfModule mod_authz_core.c>
    Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
    Order deny,allow
    Deny from all
</IfModule>
</Files>

# END Wordfence WAF

我想将我的子域重定向到主域。

问题是如果我点赞,subdomain.example.net/anystring 它会成功重定向到example.net

但是,如果我点赞,subdomain.example.net/anystring?anytext 会成功重定向到 example.net?anytext

所以这里附加了?anytext,我需要删除附加到subdomain.example.net的所有内容

我尝试了几件事,但都不成功。

我会为此请求您的帮助。

【问题讨论】:

    标签: .htaccess redirect http-redirect


    【解决方案1】:

    添加?以防止查询字符串附加到替换url,因此在代码中更改这两行:

    RewriteRule . "http://www.example.net/" [R=301,L]
    

    通过这个:

    RewriteRule . "http://www.example.net/?" [R=301,L]
    

    还有这一行:

    RewriteRule ^(.*)$ "http://www.example.net/$1" [R=301,L]
    

    通过这个:

    RewriteRule ^(.*)$ "http://www.example.net/$1?" [R=301,L]
    

    【讨论】:

    • 嗨,这解决了问题,但还有一件事,如果 URL 类似于 subdomain.example.net/anytext?d,它会重定向到 example.net?d
    • 更改这一行 RewriteRule 。 “example.net?” [R=301,L] 到这个 RewriteRule ^(.*)$ "example.net/$1?" [R=301,L]
    • 好的,谢谢,请您帮我看看如何将http://www.exaple.com/?extratext=1 重定向到http://www.example.com/
    猜你喜欢
    • 1970-01-01
    • 2023-01-09
    • 1970-01-01
    • 2010-11-06
    • 1970-01-01
    • 2019-07-23
    • 1970-01-01
    • 2014-12-10
    • 2021-01-03
    相关资源
    最近更新 更多