B2B Marketing Insights by Ironpaper

PHP 301 Redirect Code

Written by Ironpaper | October 17, 2010

Here is how to use PHP to create a permanent 301 redirect. This type of redirect tells user-agents that the webpage has moved permanently to the new, referenced location. Using 301 redirects can be a vital part of a search engine optimization (SEO) practice.

In order to use this code properly, you will need to place the PHP snippet above all content on the page. By placing the PHP 301 redirect code within or below other content will result in an error like the following: Warning: Cannot modify header information - headers already sent by...

<?php
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: https://test.com" );
?>

Please note: Replace "https://test.com" with your new location for the webpage.