删除重定向时附加的查询参数

Remove the query parameters that are appended while redirection

我有 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/" [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

的所有内容

我尝试了一些方法但没有成功。

我会请求你的帮助。

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

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

通过这个 :

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

和这一行:

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

通过这个 :

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