Tutorial Ref.com

How to Create a Permanent 301 Redirect with PHP

Tutorial Ref >> PHP Tutorials >> Permanent 301 Redirect PHP

Date modified - June 10, 2009

Here's how to quickly create a 301 permanent redirect using PHP. Once you have changed your DNS settings with your domain registrar and you've allowed some time (around a couple days on average) to lapse for the DNS settings to propogate to the worldwide servers then you can procced to your hosting company's control panel and add in your new domain. I have CPanel as my control panel. The CPanel will automatically create a new folder with the domain's name in your FTP. Then all you really need to do now is create a new index.php file using your IDE or something like notepad (for Windows) or TextPad (Mac) and place this code in the new file:

1
2
3
4
5
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://bestirarescue.com/");
exit();
?>

For one of my clients he has registerd his company's name (Estate Street Partners) as estatestreetpartners.com but it was not the same as the website's URL. This may seem odd to business owners; however, when it comes to SEO (Search Engine Marketing) there are reasons why, in some cases, it's better to use a different domain name than the business name. I don't say this for all cases but that discussion is for another day.

Once you're done then simply upload the file to the domain's root folder.

TutorialRef.com - tutorials, guides, how-tos, helps