首页 > 解决方案 > 从 URL 中删除 ?fbclid 查询字符串

问题描述

我有以下 .htaccess 规则:

RewriteEngine on
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)\/* index\.php?slug=$1

主要思想是捕获链接并将它们发送到调度程序,如果某些 RegEx 规则适用,该调度程序将调用 php 文件。一切都被发送到 index.php,它进行 RegEx 比较。@CBroe,我尝试匹配一个 URL 模式,然后根据“规则”=>“脚本”数组选择正确的 php 来调用。见下文。

补充:@iainn,这是一个古老的系统,灵感来自 WordPress 的“漂亮 URL”。我现在不能简单地重写它,我不允许为此分配办公时间。

例如:

$nodes = array(
    '/posts\/(?P<slug>.+)(\/*)$/'=>'posts.php',
    '/home(\/*)$/'=>'home.php',
)

在 Facebook 开始在 URL 的末尾添加 ?fcbid 查询字符串之前,一切都很好。补充:@CBroe,现在它只是匹配规则失败,因为它们不期望查询字符串。

补充:正如@Adam S.所建议的,一些有效的例子:

http://something.com/posts/1589285645-title-of-a-post
http://something.com/posts/1589285645-title-of-a-post/
http://something.com/home
http://something.com/home/

以下不起作用

http://something.com/posts/1589285645-title-of-a-post?fbclid=whatever
http://something.com/posts/1589285645-title-of-a-post/?fbclid=whatever
http://something.com/home?fbclid=whatever
http://something.com/home/?fbclid=whatever

我已经在这里尝试了几篇关于处理这个问题的建议,但这些都不适用于我的设置。

我应该如何重新格式化我的 .htaccess 文件来完成这个?

谢谢!

标签: php.htaccessmod-rewrite

解决方案


你可以试试这个规则:

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?slug=$1 [L,QSA]

推荐阅读