Skip to content

Instantly share code, notes, and snippets.

@jost125
Forked from jakubkulhan/gist:ac02cf43568d3156871f
Last active August 29, 2015 14:15
Show Gist options
  • Save jost125/19209f2c0265a246ef17 to your computer and use it in GitHub Desktop.
Save jost125/19209f2c0265a246ef17 to your computer and use it in GitHub Desktop.
set $utm_hash "";
if ($args ~* "^(.*&?)utm_source=([a-zA-Z0-9._-]*)(&(.*))?") {
set $args $1$4;
set $utm_hash "$utm_hash&utm_source=$2";
}
if ($args ~* "^(.*&?)utm_medium=([a-zA-Z0-9._-]*)(&(.*))?") {
set $args $1$4;
set $utm_hash "$utm_hash&utm_medium=$2";
}
if ($args ~* "^(.*&?)utm_campaign=([a-zA-Z0-9._-]*)(&(.*))?") {
set $args $1$4;
set $utm_hash "$utm_hash&utm_campaign=$2";
}
if ($args ~* "^(.*&?)utm_content=([a-zA-Z0-9._-]*)(&(.*))?") {
set $args $1$4;
set $utm_hash "$utm_hash&utm_content=$2";
}
if ($args ~* "^(.*&?)utm_term=([a-zA-Z0-9._-]*)(&(.*))?") {
set $args $1$4;
set $utm_hash "$utm_hash&utm_term=$2";
}
if ($args ~* "^(.*)&$") {
set $args $1;
}
if ($utm_hash ~* "^&(.*)$") {
set $utm_hash $1;
}
set $redirect "";
if ($utm_hash != "") {
set $redirect "H";
}
if ($args != "") {
set $redirect "Q$redirect";
}
if ($redirect = "QH") {
rewrite "(.*)" $1?$args#$utm_hash? permanent;
}
if ($redirect = "H") {
rewrite "(.*)" $1#$utm_hash? permanent;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment