从网址中删除?fbclid查询字符串

时间:2020-05-11 17:56:25

标签: php .htaccess mod-rewrite

我有以下.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文件来完成此操作?

谢谢!

1 个答案:

答案 0 :(得分:1)

您可以尝试以下规则:

   df <- select(flags, name) %>% filter(str_detect(flags$name, "^Al"))

print(df)

    name
1 Albania
2 Algeria