Skip to content

Instantly share code, notes, and snippets.

@reanim8ed
Last active July 5, 2022 07:38
Show Gist options
  • Save reanim8ed/589bc89d5b82446f1efb749d74c7d1eb to your computer and use it in GitHub Desktop.
Save reanim8ed/589bc89d5b82446f1efb749d74c7d1eb to your computer and use it in GitHub Desktop.
[Remove tracking query strings from url] #nginx

UTM

#remove utm query string
if ($args ~* "utm_") {
    #? in uri? drops the utm query string
    rewrite ^(.*)$ $uri? permanent;
}

FB

map $request_uri $redirect_fbclid {
  "~^(.*)(?:[?&]fbclid=[a-zA-Z0-9_-]+)$"  $1;
}

if ( $redirect_fbclid ) {
  return 301 $redirect_fbclid;
}

For apache, could be done using mod_rewrite

RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.+?&|)fbclid=[^&]*(?:&(.*)|)$
RewriteRule ^ %{REQUEST_URI}?%1%2 [R=301,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment