Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

QUERY_STRING not matching in rewrite?

Status
Not open for further replies.

youradds

Programmer
Jun 27, 2001
817
GB
Hi,

I'm trying to get a rewrite rule where it has p=analytics, to goto the homepage of my site (I've set it to google.com, just to make it more obvious when its working);



..the rule I have is:

Code:
RewriteCond %{QUERY_STRING} analytics
RewriteRule .*  [URL unfurl="true"]http://www.google.com/[/URL] [R=301,L]

But all that does, is load the page? (I'm trying to filter it out, as the page isn't used any more)

Any suggestions?

TIA

Andy
 
Andy,

I tested this:

Code:
RewriteEngine on
RewriteCond %{QUERY_STRING} analytics
RewriteRule (.*) [URL unfurl="true"]http://www.google.com?[/URL] [R=301,L]

And it redirected as expected. Also, without the ? at the end of the destination URL, the query string will get appended to the destination URL.

Hope that helps.

John
 
Hi,

Thanks for the reply. Mmm, weird - maybe a caching issue or something. Will have another play with it later :)

Cheers

Andy
 
Try this...
Code:
RewriteCond %{QUERY_STRING} [b]^(.*)p=analytics(.*)$ [NC][/b]
RewriteRule .*  [URL unfurl="true"]http://www.google.com/[/URL] [R=301,L]

# or just

RewriteCond %{QUERY_STRING} [b]^(.*)analytics(.*)$ [NC][/b]
RewriteRule .*  [URL unfurl="true"]http://www.google.com/[/URL] [R=301,L]
On some of my systems, the QUERY_STRING is everything appearing after the question mark ("?"), so the "p=" needs to be part of the condition, or you need to have wild cards to catch it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top