in PHP

How To 301 Redirect With PHP

PHPSearch engines index pages by the URL of the page, if these pages are moved to a different URL then the search engines will have indexed a page that no longer exists. Therefore people search in the search engine and find your people, click through to your website and they will get a 404 message. This is not only a bad user experience but also bad SEO, search engines do not want to index 404 pages. If you move an index page to a different URL you need to make sure you do a 301 redirect to the correct page. A 301 redirect will tell the search engines that this page has been permanently moved to a new location and to change the index to the new URL. You can easily do this in PHP by changing the HTTP header. Copy the following snippet to the top of the moved page to 301 it to the new location.

Header( "HTTP/1.1 301 Moved Permanently" ); 
Header( "Location:" );

Upgrade to access all content on Paulund

Members unlock all tutorials and snippets

Access to all downloadable content

Access to code examples before others

Sign Up Now

Already a member? Login here

Subscribe To The Weekly Newsletter

Get weekly updates to your email