Skip to content

Instantly share code, notes, and snippets.

@lynt-smitka
Last active November 6, 2023 13:10
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save lynt-smitka/d4bbf91855fd3a5cd5cd78e0e210116d to your computer and use it in GitHub Desktop.
Save lynt-smitka/d4bbf91855fd3a5cd5cd78e0e210116d to your computer and use it in GitHub Desktop.
Remove fbclid argument from the URL in .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*?)(&?fbclid=[a-zA-Z0-9_-]+)$
RewriteRule ^(.*)$ /$1?%1 [L,NE,R=301]
</IfModule>
@pcbnl
Copy link

pcbnl commented Nov 24, 2021

Perfect

@bafmaamy
Copy link

Thank you

@rubikvn99
Copy link

rubikvn99 commented Jul 29, 2023

Remove all queries.

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{QUERY_STRING} ^(.*?)(&?[a-zA-Z0-9_-]+=[a-zA-Z0-9_-]+)$
  RewriteRule ^(.*)$ /$1?%1 [L,NE,R=301]
</IfModule>

@dorankin
Copy link

dorankin commented Sep 3, 2023

Thanks!

@JonathanFW
Copy link

This :

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.?)(&?fbclid=[a-zA-Z0-9_-]+)$
RewriteRule ^(.
)$ /$1?%1 [L,NE,R=301]

Removes a reference to a subfolder as well. And redirects to the root of the domain. Why is that?
How do I change RewriteRule ^(.*)$ /$1?%1 [L,NE,R=301] - so that when a subfolder is referenced like:
https://domain.com/subfolder/?fbclid=blabla it simply removes: ?fbclid=blabla and redirects to: https://domain.com/subfolder/ (With a slash)

@lynt-smitka
Copy link
Author

@JonathanFW It should work.

The %{QUERY_STRING} ^(.*?)(&?fbclid=[a-zA-Z0-9_-]+)$ matches if query string contains: some params at start (call it A) + optional & + fbclid= + blabla.

Then the rewrite itself takes complete path ^(.*)$ (subfolder/ in your case - call it B). The final URL will be /B?A = /subfolder/ (A is empty and apache clears the ?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment