Forum Moderators: phranque

Message Too Old, No Replies

Redirect with tracking parameters

each parameter to a new page

         

wheel

7:31 pm on May 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



www.example.com/index.php?tracking=1
www.example.com/index.php?tracking=2

Need to redirect this to
www.example.com/index1.html and
www.example.com/index2.html

Getting lots of interesting errors :) But no redirect. Tried this:
RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} ^www\.example.com\/index.php?tracking=$
RewriteRule (.*) http://www.example.com/index$1\.html [R=Permanent]

No joy. Any help? (only have two pages I want to redirect.)

g1smd

8:13 pm on May 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Add a preceding RewriteCond looking at the QUERY_STRING value. RewriteRule cannot see the appended query string value.

RewriteRule sees only the path part of the requested URL. HTTP_HOST sees only the domain name.

This question comes up in some form or another almost every day, so there's plenty of prior threads with example code.

What do you want to happen to requests for
http://example.com/index.php?tracking=1
here? At present those would not be redirected.

I guess you should either remove the HTTP_HOST check, or else modify it to check both example.com and www.example.com too.

jdMorgan

9:25 pm on May 28, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's important to use the right variables for the right purposes...

RewriteCond %{QUERY_STRING} ^tracking=([12])$
RewriteRule ^index\.php$ http://www.example.com/index%1.html? [R=301,L]

should work, assuming that "tracking=1" and "tracking=2" are the literal desired values.

This code also assumes that index1.html and index2.html are NOT going to be internally rewritten back to the index.php script with those same name/values in the query. In other words, if you're trying to correct a script filepath that got exposed as a URL, then further steps will be needed to prevent an infinite redirect/rewrite loop.

Jim