Redirecting web pages using 301
If you need to change the address of a page that appears in Google's search engine results, you'll need to use a server-side 301 redirect. The 301 status indicates that the page has permanently moved to a new location. When Google (or any other search engine) sees a 301 redirect it knows that the page has changed location and will carry any link weighting from the original page to the new URL.
It is possible to redirect in two different ways: using the web server or using server side code, such as PHP.
301 Redirect using Apache
To redirect using Apache, you'll need to have mod_rewrite enabled. Most apache installations will have mod_rewrite installed by default. To check to see if the module is installed, add the following line to the apache configuration file or to an applicable .htaccess file:
` RewriteEngine On
Now you know mod_rewrite is enabled, you can add your rewrite rule to either the apache configuration file or a .htaccess file. To redirect you'll need to use a RedirectMatch directive. Here are some examples:
RedirectMatch 301 /category/education.php http://gazhall.com
RedirectMatch 301 /category/(.*) /$1
RedirectMatch 301 /category/categorydetail.php(.*) http://gazhall.com/newcat.php$1
See here for the official Apache documentation on this subject.
301 redirect using PHP
If you don't have access to the webserver but do have access to php, then you can redirect using PHP. This is a lot quicker and can be done by inserting the following code into a webpage that you want to redirect:
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://gazhall.com/newpage.php");
?>
Using the web server option is preferable if you have lots of redirects to make, but for a quick and easy redirect then the php option is just as good. Most SEO experts prefer the Apache option, but both are regarded by the search engines to be as good as each other.
This article was written by Gaz Hall, a UK based SEO Consultant on 1st September 2015.
Gaz has 20 years experience working on SEO projects large and small, locally and globally across a range of sectors.
If you need any SEO advice or would like him to look at your next project then get in touch to arrange a free consultation.