vForums Support > Programming & Coding :: Programming Discussion :: > Domain Change Redirection

Domain Change Redirection - Posted By ashkir (ashkir) on 15th Jan 10 at 10:51am
Lets say I change my domain to newsite.com from dancingwithross.com. So how can I get dancingwithross.com/index.php/pagetitle=nightclub to redirect to newsite.com/index.php/pagetitle=nightclub ? This I want to do because a login has to be done separately on both, and needing to change thousands of links to the new domain, so redirection would be easier.

Re: Domain Change Redirection - Posted By Marc (cr0w) on 15th Jan 10 at 11:29pm
<?php

header("Location: http://newsite.com" . $_SERVER['REQUEST_URI']);

?>

{Smile}

Re: Domain Change Redirection - Posted By ashkir (ashkir) on 16th Jan 10 at 1:14am
Would this work, for say a PHPBB forum? Where both domains are tied to the same exact host?

Re: Domain Change Redirection - Posted By Marc (cr0w) on 16th Jan 10 at 2:03am
 
Would this work, for say a PHPBB forum? Where both domains are tied to the same exact host?


The REQUEST_URI statement returns everything after (and including) the "/", so it will work for any page, provided that code snippet is on it. I know there's also a way to do it with .htaccess, but I'm not very good with that, so Ross will probably have to help you out with that. {Wink}

Re: Domain Change Redirection - Posted By Michael (wrighty) on 16th Jan 10 at 3:49am
 
<?php

header("Location: http://newsite.com" . $_SERVER['REQUEST_URI']);

?>

{Smile}


Surely that'd constantly loop, an IF statement is required! {Wink}

Re: Domain Change Redirection - Posted By Marc (cr0w) on 16th Jan 10 at 7:56pm
 
 
<?php

header("Location: http://newsite.com" . $_SERVER['REQUEST_URI']);

?>

{Smile}


Surely that'd constantly loop, an IF statement is required! {Wink}


From what I understand, he will have two copies of the site. If he is running both sites off the exact same files, then yes, he will need an if statement. {Wink}

If I misunderstood, though, you would need this code:

<?php


if($_SERVER['SERVER_NAME'] == "www.oldsite.com")
{

header("Location: http://newsite.com" . $_SERVER['REQUEST_URI']);

}
?>

Re: Domain Change Redirection - Posted By ashkir (ashkir) on 19th Jan 10 at 1:54pm
 
 
 
<?php

header("Location: http://newsite.com" . $_SERVER['REQUEST_URI']);

?>

{Smile}


Surely that'd constantly loop, an IF statement is required! {Wink}


From what I understand, he will have two copies of the site. If he is running both sites off the exact same files, then yes, he will need an if statement. {Wink}

If I misunderstood, though, you would need this code:

<?php


if($_SERVER['SERVER_NAME'] == "www.oldsite.com")
{

header("Location: http://newsite.com" . $_SERVER['REQUEST_URI']);

}
?>


That works! Thank's marc!