Michael Michael - 1 year ago 72
Apache Configuration Question

Redirect to same path on new domain

Hi I've got a new domain and want to redirect my users to the new domain's equivalent path.

So if they go on: oldsite.com/money.php?value=1

Then it should direct them to: newsite.com/money.php?value=1

I have the same header.php for all the pages, so can this be done with a simple php line?

Answer Source

I will give you 2 functions which could be useful for some other thing;

function currentURL() {
     $pageURL = 'http';
     ($_SERVER["SERVER_PORT"] === 443) ? $pageURL .= "s" : '';
     $pageURL .= "://";
     if ($_SERVER["SERVER_PORT"] != "80") {
     } else {
     return $pageURL;

function redirect2NewDomain () {
$url = currentURL();
   return false;
# Get the url parts
$parts = parse_url($url);
Header( "Location : {$parts['scheme']}://{$parts['host']}" );

Ofcourse using .htaccess is much more easier and will be better for SEO;

RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L] 

I hope this helps

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download