How to make 301 redirect in PHP using header() function

As you can set up 301 redirect using htaccess, you can also make this type of redirection using PHP, this can be done using the function header() in PHP, the function header() is used to send a raw HTTP header, so we can make use of it to send redirect info in HTTP protocol, suppose that we want to redirect the current page to the new domain, the following code will do it.

header(“HTTP/1.1 301 Moved Permanently”);

Remember to use this code in the head of the page, and before any echo or output.

  1. No comments yet!, be the first to post a comment.

Your email will not be published, The required fields marked with '*'