PHP Redirect


PHP Tutorial > Redirect

If you have moved your pages, you can use PHP to perform a redirect to your new page.

The search engine friendly way of redirecting is the 301 redirect. In PHP, this is implemented as follows:

<?
Header("HTTP/1.1 301 Moved Permanently");
Header("Location:http://www.new-site.com");
?>

Make sure the above code is included before any HTML is produced. Otherwise, the redirect will not work.

A 301 redirect directs the search engine spiders to the new page, and ensures that all link juices to your old page are all passed to the new page.

Please note that if you do not include the first Header line above, the redirect still works. But, instead of a 301 redirect, now it becomes a 302 (temporary) redirect. 302 redirects are not search engine friendly, as it has become a common spam technique. So, if you want to ensure your search engine ranking is not affected by moving your file elsewhere or changing your file name, make sure you set up a 301 redirect.

Next: PHP MySQL





Copyright 1keydata.com 2007, 2008, All Rights Reserved.   Privacy Policy



PHP Tutorial
PHP Variables
PHP Operators
PHP IF ELSE
PHP ELSEIF
PHP Switch
PHP While Loop
PHP FOR Loop
PHP DO WHILE Loop
PHP FOREACH Loop
PHP INCLUDE
PHP Functions
PHP ARRAY
PHP FORMS
PHP Cookies
PHP Redirect
PHP MySQL

PHP Commands

Resources