Url rewriting htaccess重写规则如果url包含特定单词,请保留url的其余部分

Url rewriting htaccess重写规则如果url包含特定单词,请保留url的其余部分,url-rewriting,Url Rewriting,Facebook最近添加了一个跟踪脚本/参数:&fbclid=。。。。 因此,当人们点击Facebook页面上指向我的网站(公文包)的链接时,我的网站无法找到正确的页面 例如: 这是facebook创建的url: 我的网站很快将其更改为: 这将导致找不到该页。所以我想做的是: 如果url包含&fbclid,请删除此部分并保留url的其余部分。因此,如果我以URL为例,则需要如下所示: 我提出了以下重写规则: RewriteCond %{QUERY_STRING} “fbclid=” [NC]

Facebook最近添加了一个跟踪脚本/参数:&fbclid=。。。。 因此,当人们点击Facebook页面上指向我的网站(公文包)的链接时,我的网站无法找到正确的页面

例如:
这是facebook创建的url:

我的网站很快将其更改为:

这将导致找不到该页。所以我想做的是:
如果url包含&fbclid,请删除此部分并保留url的其余部分。因此,如果我以URL为例,则需要如下所示:

我提出了以下重写规则:

RewriteCond %{QUERY_STRING} “fbclid=” [NC]
RewriteRule (.*) /$1? [R=301,L]

但这两条规则都不能解决问题。 有人能帮我吗

这是我当前的.htaccess

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1 [QSA]
SetOutputFilter DEFLATE

<FilesMatch ".(eot|ttf|otf|woff|woff2)">
 Header set Access-Control-Allow-Origin "*"
</FilesMatch>

<IfModule mod_expires.c>
   ExpiresActive on

   ExpiresByType image/jpg "access plus 1 month"
   ExpiresByType image/jpeg "access plus 1 month"
   ExpiresByType image/gif "access plus 1 month"
   ExpiresByType image/png "access plus 1 month"
</IfModule>
Options+FollowSymLinks
重新启动发动机
重写cond%{SCRIPT_FILENAME}-D
重写cond%{SCRIPT_FILENAME}-F
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?页面=$1[QSA]
SetOutputFilter放气
标题集访问控制允许原点“*”
过期于
ExpiresByType图像/jpg“访问加1个月”
过期按类型图像/jpeg“访问加1个月”
ExpiresByType image/gif“访问加1个月”
ExpiresByType图像/png“访问加1个月”

我找到了解决问题的方法

RewriteCond %{QUERY_STRING} ^(.*)&?fbclid=[^&]+&?(.*)$ [NC]
RewriteRule ^(.*)$ /$1?%1%2 [R=301,L]

希望它能在将来帮助别人

@Bram的解决方案在我的Wordpress中发挥了作用。这是前后的.htaccess代码

之前:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On    
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
#开始WordPress
重新启动发动机
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#结束WordPress
之后:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*)&?fbclid=[^&]+&?(.*)$ [NC]
RewriteRule ^(.*)$ /$1?%1%2 [R=301,L]

RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
#开始WordPress
重新启动发动机
RewriteCond%{QUERY_STRING}^(.*)和?fbclid=[^&]+&(.*)$[NC]
重写规则^(.*)$/$1?%1%2[R=301,L]
重写基/
重写规则^index\.php$-[L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则/index.php[L]
#结束WordPress
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*)&?fbclid=[^&]+&?(.*)$ [NC]
RewriteRule ^(.*)$ /$1?%1%2 [R=301,L]

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