Link to home
Start Free TrialLog in
Avatar of dauyeung
dauyeungFlag for Canada

asked on

PHP Script for URL Redirect with parameters


I need to redirect all requests to one domain and redirect it to another.  However, I need it to redirect with all the parameters.

I can put a php page on a domain.

I have a main domain (e.g. and a short domain (e.g.  

I have recently moved my corporate website into a fully hosted environment.  Previously, we hosted the proprietary CMS.  In my setup, I had IIS forward all requests for to, including all parameters after the domain.

So  IIS would redirect requests for to  It was a wildcard redirect, so it would work for any URL, not just predesignated ones, such as:

Redirect request for: 


Thank You.
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

You can use PHP header("Location") to do this redirection.  I'll show you an example as soon as I can find it in my library.
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dauyeung


I'm new to PHP, I'm guessing that you missed the ?> at the end.
Good point, but no, I deliberately omitted the close-PHP tag.  The ?> at the end is useless and should be avoided if at all possible.  The only permissible use of the close-PHP tag is when the PHP script must stop so HTML can start.  In professionally written PHP applications this happens very, very rarely.
Great.  Thanks.  It works, if I directly request the URL.  ie.

But it doesn't work for other pages, e.g.

Any ideas?  I'm thinking that it's more to do with the host setup than anything.
There is a difference between PHP pages and ASPX pages, and this question was only posted in the PHP Zone.  Sorry but I reflexively responded with only the basic PHP solution.  Maybe you can ask the EE moderators to add it to other EE Zones.

Why did you give a bad grade?  Why didn't you follow the recommendation to get a moderator to help?

I gave you a tested-and-working code example based on all of the information you provided in the question.  Please see the grading guidelines here and please explain the grade as required by the guidelines.

Thank you.
Sorry.  According to the page you described, you do deserve an Excellent.  Do you know the best way to change the rating?  Looks like I need to post another request.
You can use "Request Attention" if you want to ask a moderator for assistance. The link is typically near the original question.  Thanks for your consideration.