How To Redirect Domains with PHP Print

  • 0

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.


Was this answer helpful?

« Back