tholo tholo - 1 month ago 20
PHP Question

Redirect with Dynamic Parameters in URL

I do not know how to format this question to be clear enough, so please bear with me. I will do my best.

Lets say I want to redirect one url to another, i.e:

www.site1.com ==> www.site2.com


Now, let's say the first url has parameters
name
and
email
so it looks like:

www.site1.com/?name=SOMETHING&email=SOMETHING


and the values under name and email are dynamic ones.

Is there a way to make a script which will automatically know how to redirect this:

www.site1.com/?name=SOMETHING&email=SOMETHING ==> www.site2.com/?name=SOMETHING&email=SOMETHING


Thanks.

Answer

You can use the following rule in site1/.htaccess :

RewriteEngine on

RewriteCond %{QUERY_STRING} name=.+&email=.+ [NC]
RewriteRule ^ http://site2.com/ [L,R]

This will redirect http://site1.com/?name=something&email=something to http://site2.com/?name=something&email=something