Friday, April 6, 2012

How to Set a Permanent 301 Redirect Using PHP ?

Setting up a permanent 301 redirect is quite easy for users having Cpanel or similar control panel. But what if we are using a webserver that does not support the .htaccess file ?

Here below is the code that you can use in a php file to set a permanent 301 redirect.

PHP Code:
<?php
Header
"HTTP/1.1 301 Moved Permanently" );
Header("Location: http://www.google.com");
?>
Just edit the destination url and place the code in your file that you want to redirect.

Note: This code should be at top and before any output code.

No comments:

Post a Comment