【问题标题】:How to remove specific QUERY_STRING parameter in .htaccess如何删除 .htaccess 中的特定 QUERY_STRING 参数
【发布时间】:2022-01-04 06:12:35
【问题描述】:

我需要一个适当的解决方案来删除 URL 参数。

例子:

输入:https://www.hostever.com/blackfriday/?fbclid=IwAR3s1aVKUQELAb0EGW9_mh4qyR-i9ZqfNjFFB6xv_MoNRal2cH--lKofqHM

输出:https://www.hostever.com/blackfriday/

所以它会删除 fbclid=

Input: https://www.hostever.com/?s=blogger
Output: https://www.hostever.com/?s=blogger
No need to change other parameters except **fbclid=**

我(只需要从 URL 中删除 fbclid= 这个。

现在我正在使用它,但问题在于参数太多。

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{QUERY_STRING} !=""
 RewriteCond %{QUERY_STRING} !^p=.*
 RewriteCond %{QUERY_STRING} !^action=.*
 RewriteCond %{QUERY_STRING} !^s=.*
 RewriteCond %{REQUEST_URI} !^/wp-admin.*
 RewriteRule ^(.*)$ /$1? [R=301,L]
</IfModule>

请帮助我,如何使用 .htaccess 从 URL 中删除特定参数?

【问题讨论】:

    标签: .htaccess parameters query-string


    【解决方案1】:

    我已经改编了Mod_rewrite delete parameter in 301 Redirect的答案:

    # Remove fbclid when it is the only URL parameter
    RewriteCond %{QUERY_STRING} ^fbclid=[^\&]*$ 
    RewriteRule ^(.*)$ /$1 [R=301,L]
    # Remove fbclid when it is the last URL parameter
    RewriteCond %{QUERY_STRING} ^(.*)fbclid=[^\&]*$ 
    RewriteRule ^(.*)$ /$1?%1 [R=301,L]
    # Remove fbclid when it is in the middle of the URL parameters
    RewriteCond %{QUERY_STRING} ^(.*)fbclid=[^\&]*\&(.*)$ 
    RewriteRule ^(.*)$ /$1?%1%2 [R=301,L]
    
    • [^\&amp;]* 是不是&amp; 的任意数量的字符,即。一个参数值。
    • $1 是从重写规则的括号中捕获的组
    • %1 是重写条件中第一组括号中捕获的组。
    • %2 是重写条件中第二组括号中捕获的组

    我没有看到将其作为单一规则实施的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-09
      • 2016-05-25
      • 2014-02-26
      • 1970-01-01
      • 2016-10-09
      • 1970-01-01
      相关资源
      最近更新 更多