Skip to content

Instantly share code, notes, and snippets.

@lynt-smitka
Created June 11, 2019 07:39
Show Gist options
  • Save lynt-smitka/b8bf0a4b7e2a9e5802faa48ee16b19b0 to your computer and use it in GitHub Desktop.
Save lynt-smitka/b8bf0a4b7e2a9e5802faa48ee16b19b0 to your computer and use it in GitHub Desktop.
if ($query_string ~ "^(?<pre>.*?)(&?fbclid=[a-zA-Z0-9_-]+)(?<post>.*?)$"){
rewrite ^(.*)$ $1?$pre$post?;
}
if ($query_string ~ "^(?<pre>.*?)(&?utm_source=[a-zA-Z0-9_-]+)(?<post>.*?)$"){
rewrite ^(.*)$ $1?$pre$post?;
}
if ($query_string ~ "^(?<pre>.*?)(&?utm_medium=[a-zA-Z0-9_-]+)(?<post>.*?)$"){
rewrite ^(.*)$ $1?$pre$post?;
}
if ($query_string ~ "^(?<pre>.*?)(&?utm_campaign=[a-zA-Z0-9_-]+)(?<post>.*?)$"){
rewrite ^(.*)$ $1?$pre$post?;
}
if ($query_string ~ "^(?<pre>.*?)(&?utm_term=[a-zA-Z0-9_-]+)(?<post>.*?)$"){
rewrite ^(.*)$ $1?$pre$post?;
}
if ($query_string ~ "^(?<pre>.*?)(&?utm_content=[a-zA-Z0-9_-]+)(?<post>.*?)$"){
rewrite ^(.*)$ $1?$pre$post?;
}
if ($query_string ~ "^(?<pre>.*?)(&?gclid=[a-zA-Z0-9_-]+)(?<post>.*?)$"){
rewrite ^(.*)$ $1?$pre$post?;
}
@erikdemarco
Copy link

@lynt-smitka Your nginx config will cause 500 error if nginx rewrite more than 10x.

Read it here:
=> http://nginx.org/en/docs/http/ngx_http_core_module.html#internal

For example: example.com/?gclid=222&gclid=222&gclid=222&gclid=222&gclid=222&gclid=222&gclid=222&gclid=222&gclid=222&gclid=222&gclid=222&gclid=222&gclid=222&gclid=222&gclid=222&gclid=222&gclid=222&gclid=222&gclid=222&gclid=222&gclid=222&gclid=222&gclid=222&gclid=222

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