send all requests to different url with variables intact

Using mod_rewrite to handle various content issues

send all requests to different url with variables intact

Postby captain-caveman » Fri May 25, 2007 10:44 pm

I want to direct all traffic from one url to a different site but want to send any variables with it.

I have code that is working but am wondering if I am covering all my bases.

.htaccess at firstURL:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*)?var=(.*)$ [NC]
RewriteRule ^(.*)$ http://www.differentURL.com/varHandler.php [R=301,L]

RewriteRule ^(.*)$ http://www.differentURL.com/$1 [R=301,L]


In my mind the first Cond/Rule is handling the passing of the variables and the second Rule is handling visits to firstURL when no variables are present.

I think I handle variable checking pretty good at differentURL so I am thinking I don't have to check for any nefarious tampering at the firstURL.

I guess my two headed question: is this the most efficient way to accomplish what I want, and am I missing any details to handle any weird scenarios?
captain-caveman
 
Posts: 4
Joined: Fri May 25, 2007 10:13 pm

Postby richardk » Mon May 28, 2007 7:42 am

If you want domain_one.com/page.php?querystring to domain_two.com/page.php?querystring and domain_one.com/somethingelse.php?querystring to domain_two.com/somethingelse.php?querystring, etc. put this in a .htaccess file in domain_one.com's document root
Code: Select all
Redirect 301 / http://domain_two/


Or if you want domain_one.com/page.php?querystring and domain_one.com/somethingelse.php?querystring to domain_two.com/varHandler.php?querystring what you have should be fine.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby captain-caveman » Mon May 28, 2007 7:20 pm

Excellent. Thank you very much for your input.
You are an invaluable resource for how to use this powerful module.
captain-caveman
 
Posts: 4
Joined: Fri May 25, 2007 10:13 pm


Return to Content

Who is online

Users browsing this forum: No registered users and 4 guests

cron