Skip to content

Instantly share code, notes, and snippets.

@insparrow
Created June 27, 2014 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save insparrow/74ca7a828fbce00b79d1 to your computer and use it in GitHub Desktop.
Save insparrow/74ca7a828fbce00b79d1 to your computer and use it in GitHub Desktop.
Using mod_rewrite to preserve url args (such as gclid) throughout your site
RewriteEngine on
# If 'gclid' argument exists in referring URL and this is an article,
# append argument to requested URL.
RewriteCond %{QUERY_STRING} !^gclid=
RewriteCond %{REQUEST_URI} ^/articles\/(.*)$ [NC]
RewriteCond %{HTTP_REFERER} ^(.*)?gclid=([^&]+)
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1?gclid=%2 [QSA,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment