htaccess Rewriterule 如果 url 包含特定单词,则保留 URL 的其余部分 [英] htaccess Rewriterule if url contains a specific word, keep the rest of URL
问题描述
Facebook 最近添加了一个跟踪脚本/参数:&fbclid=....因此,当人们点击 Facebook 页面中指向我的网站(投资组合)的链接时,我的网站无法找到正确的页面.
Facebook recently added a tracking script/parameter: &fbclid=.... So when people click on a link from a Facebook page which refers to my website (portfolio), my website can't find the right page.
一个例子:
这是 facebook 创建的 url:我的网站很快就变成了:
http://stanbroeksteeg.nl/portfolio?video=296818340&fbclid
My website quickly changes it to:
http://stanbroeksteeg.nl/portfolio?video=296818340&fbclid
这会导致找不到页面.所以我想做的是以下内容:
如果 url 包含 &fbclid 删除这部分并保留 URL 的其余部分.因此,如果我以示例 URL 为例,则需要如下所示:
http://stanbroeksteeg.nl/portfolio?video=296818340
This results in the page not being found. So what i want to do is the following:
If the url contains &fbclid remove this part and KEEP the rest of the URL. So if i take the example URL is needs to be like this:
http://stanbroeksteeg.nl/portfolio?video=296818340
我想出了这些重写规则:
I've come up with this these Rewrite rules:
RewriteCond %{QUERY_STRING} "fbclid=" [NC]
RewriteRule (.*) /$1? [R=301,L]
或
RewriteCond %{QUERY_STRING} ^(.*)&?fbclid=(.*)$ [NC]
RewriteRule ^/?(.*)$ /$1?%1 [R=301,L]
但这两条规则都不能解决问题.有人可以帮我解决这个问题吗?
But both rules do not resolve the issue. Can somebody help me with this?
这是我当前的 .htaccess
This is my current .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>
推荐答案
我找到了解决问题的方法
I found a solution for my problem
RewriteCond %{QUERY_STRING} ^(.*)&?fbclid=[^&]+&?(.*)$ [NC]
RewriteRule ^(.*)$ /$1?%1%2 [R=301,L]
希望以后能帮到别人
这篇关于htaccess Rewriterule 如果 url 包含特定单词,则保留 URL 的其余部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!