Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got an url coming in as:


This is going to a 404 page because of the gclid...

I need it to go to:


I've tried this, with no success:

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)&gclid=(.*)$  $1 [L]

All help is appreciated. Thanks.

share|improve this question

migrated from serverfault.com May 1 '11 at 7:08

This question came from our site for system and network administrators.

is there a reason you're leaving in the /index.php? I assume that's your controller script, but using rewrites, you could easily make it simply make it /location. The main issue with what you're trying to do is that you're trying to capture the QUERY_STRING (everything after the ?). You need to treat this specially in RewriteRules – djdrey May 1 '11 at 2:26
in the next set of rules i'm removing the index.php... but i'm having the issue with simply ignoring the gclid... on those adword pages only of course – Jeffrey May 1 '11 at 2:50

This is pretty much answered in concept at least here: http://stackoverflow.com/questions/2111182/rewriting-url-with-selected-query-string-parameters-in-htaccess

share|improve this answer
thanks, but i need to see it with my conditions – Jeffrey May 1 '11 at 2:48

I'm not sure how you're ending up with AdWords auto tagging appended to a URL without the proper structure but if you don't want the gclid parameter at all you could alway just switch off autotagging in AdWords. You shouldn't need to remove it using a rewrite rule as it's just an option that you can choose not to use.

share|improve this answer

Try this (you :

<IfModule mod_rewrite.c>

  RewriteEngine On
  RewriteBase /

  # Catch any Google campaigns directed to the home page
  RewriteCond %{REQUEST_URI} ^/$
  RewriteCond %{QUERY_STRING} ^(gclid=.*)
  RewriteRule ^(.*)$ /index.php/ [L,PT]

  # Everything else 

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.