PHP on page 301 redirect

I needed to redirect traffic from one page to another without using the .htaccess file.

I also wanted to let any search engines know that may have indexed the file of its new location.

By using a 301 redirect it would let search engines know to index the new page instead of the original page.

As the page was a .php I have achieved this redirect by using the following PHP (PHP: Hypertext Preprocessor) code:

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://www.example-samesite.com/new-page.php");
exit();
?>

 

You may also like...