How to setup a 301 Redirect in php

A 301 HTTP response status code is a way of telling search engines that a page, pages, directory or entire website has been permanently moved to another place on the web. This is very useful if you have changed the structure of your websites url’s or if you have moved domain. You can also redirect your entire site.
Whereas a 301 code tells search engines that something has been permanently moved, a 302 code tells search engines that something has been temporarily moved. This is useful if you only want to redirect a page for a short period of time. To do a 302 redirect simply change the 301 part to 302.
You can also use 303, which is means ’seeother’ and the page has been replaced by something else. Again, to do this simply substitute 301 with 303 in the tutorials below.

How to setup a 301 Redirect
The basic code for redirecting is :
Redirect 301 old_location new_location
 
The old location of the file has to be the absolute path from the root of your server. The new location should use http. So for example, if you want to move a file called productreview.html from the root of your site to a subdirectory called products you would use :
Redirect 301 /productreview.html http://www.yoursite.com/products/productreview.html

Comments