How to do 301 (Permanent Redirection) in PHP

It is really simple.

Just put the following 2 lines at the top of the page you are trying to redirect.

header(“HTTP/1.1 301 Moved Permanently”);
header (‘location: <<your landing page>>”);

Replace <<your landing page>> with the URL of the landing page.

Remember, you need these 2 lines before any output statement is made on your script, else you will get a ‘headers already sent’ error.

One Comment

  1. Url Shortening Service:

    The 301 Redirection is usually carried out in the root directory of the web server. Url Shortening Service

Leave a comment