Permanent Redirection with HTTP 301 using PHP

If you have permanently moved a page or website to a new URL, you must use the HTTP status code 301 Moved Permanently to indicate permanent redirection. You can easily make 301 permanent redirects using PHP by just adding two lines of code.

<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com/newURL");
?>
Add these lines at the beginning of the PHP file before any other code. It is highly recommended to redirect individual pages than the entire site.