today I would like to talk quick about the subject “Redirection with PHP”. Quick, because there is not much to say
The code for a redirect in PHP looks like that:
<?php header("Location: http://www.domain.de/seite.php"); exit(); ?>
header() is sending the HTML-header. With “Location:” you’re telling it that it is an redirect. After it you provide the URL to which the redirect it pointing to. And with
exit(); we tell the script to abort, not to execute any other code.
But I also have to mention to thing about what you do before you set an redirect. Is it a permanent redirect, because something changed in the webpage structure (for example a page got a new URL), then you should “say” that in the redirect, else it can occur problems with the search engine rankings.
A permanent redirect looks then like that:
<?php header("Status: 301 Moved Permanently"); header("Location: http://www.domain.de/seite.php"); exit(); ?>
header("Status: 301 Moved Permanently"); is sending the status code that the redirect is permanent. There are also other status codes, like the 302 code, which is for temporarily redirects.
If e.g. the Google bot comes around and gets an 301 status code for a URL, then it will save the URL change and is crawling next time straight the new page. Like that the new page gets the ranking of the old page and it doesn’t get lost.
I hope it’s helping. If not, let me have a comment