Simple Redirection
To redirect the visitor to another page (particularly useful in a conditional loop), simply use the following code:
<?php
header('Location: http://www.example.com');
?>
If ever the target page is on another server, you include the full
<?php
header('Location: http://www.example.com/mypage');
?>
HTTP Headers
Temporary/permanent redirections
By default, the type of redirection presented above is a temporary one. This means that search engines such as Google will not take into account for indexation.
So if you want to notify the search engines that the page has been permanently moved to another location:
<?php
header('Status: 301 Moved Permanently', false, 301);
header('Location: http://www.example.com');
?>
Interpretation of PHP code
The PHP code located after the header() will be interpreted by the server, even if the visitor move to the address specified in the redirection, which means that in most cases you need a method of follow the header() function of the exit() function, in order to decrease the load of the server.
<?php
header('Status: 301 Moved Permanently', false, 301);
header('Location: http://www.example.com');
?>