Redirecting Domains with PHP

Ever wanted to redirect one of your domains to point to another location?

With PHP this can easily be achieved using the 'header()' function. To redirect a request from oldsite.com to newsite.com, you could simply place the following code in the index.php file in the root of oldsite.com:

<?php
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.newsite.com" );

?>

It's as easy as that! Also, remember that if you are using cPanel (Farbyte hosting does) you can setup redirects within the Domains section of the control panel. This has the same affect as the PHP redirect, but instead uses .htaccess rules.

Trackback URL for this post:

http://www.farbyte.com/blog/trackback/7
tagged in

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.