homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Stripping the QUERY_STRING
Removing unsightly AdWords string

Msg#: 510 posted 3:46 am on Oct 29, 2003 (gmt 0)

I have recently started adding a query string to my adwords campaigns for tracking and I was hoping for this to show up in my logs (at least on the first pass) but then be removed prior to displaying the actual page.

I thought of using mod-rewrite but I guessed that that's only for rewriting the host/filename stuff.... but then I found:
When you want to erase an existing query string, end the substitution string with just the question mark.

So I tried the following but alas to no avail:
RewriteCond %{QUERY_STRING} ^gad=foo
RewriteRule (.*) http://%{HTTP_HOST}/$1/? [R=302,L]

Two questions:
1) is this possible (and where's my mistake - the 302's meant to be inoccuous and the L is there so it loops); and
2) perhaps more importantly - by stripping off the string will I ever see it in the logs (I was hoping that it would show up in the first pass and then disappear for the display and then the remainder of the logs).

I do not (yet) have my own weblog software so I was simply going to use Grep for windows to get an idea of adwords traffic.

I guess therefore - the fourth of my two questions (!) is - any better ideas for a simple analysis of adwords (but then I guess that's another forum). I'm still curious about my mod-rewrite problem though :)



WebmasterWorld Senior Member jdmorgan us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 510 posted 4:01 am on Oct 29, 2003 (gmt 0)


The code you posted should work. But I seem to recall running into problems when trying to use server variables in the substitution in .htaccess. Try this slight modification to see if that's the problem:

RewriteCond %{QUERY_STRING} ^gad=foo
RewriteCond %{HTTP_HOST} ^(.*)$
RewriteRule ^(.*)$ http://%1/$1/? [R=302,L]



Msg#: 510 posted 4:38 am on Oct 29, 2003 (gmt 0)

Hi Jim,

Thanks - actually it did work (sort of) - must've been a caching hiccup of some sort.

It put an extra slash on the end though so:

RewriteCond %{QUERY_STRING} ^gad=foo
RewriteRule (.*) http://%{HTTP_HOST}/$1? [R=302,L]

...does work BUT - alas it strips it before anything appears in my log.... I'm off to the Adwords forum I guess :)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved