Home  • Programming • PHP

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.

Comments 2


useful post
Thanks Sir.
Copyright © 2025. Powered by Intellect Software Ltd