Free PHP scripts

Host UNLIMITED Websites, $7.95 /month

PHP Redirect

You are here: PHPJunkyard > Free tutorials > PHP redirects


Sometimes you might want to redirect your visitors to a new URL address. This article will show you how to make a PHP redirect using the 301 "moved permanently" redirection. This is the one you should use as it is the most search engine friendly. Like the name suggests, PHP redirect tells the browser (or a search engine bot) that the page has been permanently moved to a new location.

PHP redirect code

To redirect people and robots to a new location use this PHP redirecting code:

<?php
header
("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.New-Website.com");
?>

Tip: use lower-case name for the header function (not Header) to make sure your PHP redirect code is compatible with PHP 6.

You could skip the 301 Moved Permanently tag and use just:

<?php
header("Location: http://www.New-Website.com");
?>

But this would result in a "302 Moved Temporarily" redirect instead of a 301 one. This should be avoided as permanent redirects are more search engine friendly and should be used where possible.

You can enter any sub-page for the location, this PHP code will redirect users to the test.php sub-page of your website:

<?php
header
("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.New-Website.com/test.php");
?>

It is important that you don't have any other code (including empty rows and spaces) before the above PHP redirect code. If you do you will get a nice headers already sent notice from PHP and the redirect will not work.

That's it! Enjoy redirecting PHP pages.

 


Copyright notice

This tutorial is copyrighted by Klemen Stirn. Obtain permission before copying, re-publishing or otherwise redistributing this article.

 


 

Thanks for support to
Email Hosting
Web Hosting
Website Hosting
Dedicated Server Hosting
cheap web hosting
Web Hosting UK
Free Web Hosting
Projector Headlights
CRM Software
Interactive marketing agency
Managed hosting
Silver Chains
SEO
PHP form
SEO Company
Online Computer Repair
Office Chairs
PHP forms
Buy PHPJunkyard author a beer (DONATE)
Other links
Web Hosting
Managed Hosting
DWI lawyer Dallas
Anxiety
Dish Network
DiscountSpies.com
Online Computer Help
Hydrocephalus Treatment

Free PHP scripts | Click counter | Link manager | Guestbook | Message board | Help Desk Software | Random Image
Text hit counter | Graphical counter | Random Text | Resources | PHP hosting | PHP books | Free tutorials
FTP/Chmod tutorial | Link to us | Help PHPJunkyard | Remove copyright | Advertise | Support Forum
Contact author | Invite a friend | Links | Donations

© Copyright 2004-2010 PHPJunkYardTM. All rights reserved. |
No part of this website may be reproduced, copied and/or distributed in any medium without express written permission
This website is not allowed to be listed in any auto-surf, pay-to-surf, pay-to-read, or pay-to-click services
Trademarks are property of their respective owners.