A 301 redirect is a permanent redirect which sends traffic that lands on an existing page to a newly created one. Not only does a 301 redirect send visitors to a new URL, but it also passes on 90-99 percent of the link juice/rankings and thus it is typically the most search engine friendly way to redirect visitors to a new page.

301 Redirects Explained

301 refers to the HTTP status code for this type of redirect, and can be performed by adding several lines of code to the .htaccess file on your server and in most cases, is the best way of implementing redirects on your website.

(301’s can also be performed at the root level of the Apache installation via the httpd.conf file, however, editing the .htaccess file is usually the most preferred method)

301 Redirects VS 302 Redirects

Unlike 302 redirects, which are often used for temporary purposes, 301 redirects are used when a page is permanently moved. 302 redirects still send users to a new URL destination but they do not transfer the SEO rankings.

For this reason, 301 redirects become a highly important SEO factor when creating a new page in place of an old one.

There are several reason you may wish to perform 301 redirects.

1. You have changed the domain of your website and wish to send all traffic to new URLs.
2. You’re merging two websites and want to make sure dead links are redirected to the correct page.
3. You have multiple URLs for your home page e.g. http://www.example.com, http://www.example.com/home and/or http://www.home.example.com. In this instance it’s best to redirect all home page links to one ‘canonical’ destination/URL.

How to Perform a 301 Redirect Apache Server

To perform a 301 redirect on Apache servers you will need to edit the .htaccess file on your server – To implement a 301 redirect on any other server, such as ISS or NGINX, you will need to contact your hosting provider.

In addition, the server must have the apache module ‘mod_rewrite’ installed, a feature which is usually installed by default.

The .htaccess file is a hidden file (represented by a ‘.’ at the beginning of the file name). To edit the file, you must remove the ‘.’ before the file can be opened with a text editor.

Before editing this file, be sure to save a copy in case anything goes wrong. Simply create a duplicate file and rename it, then you’ll always have a backup file to revert to should you run into any problems.

When editing the file be sure to use only a text-based editor such as Notepad as any formatting will cause errors in the code.

How to Enable mod_rewrite and the ReWriteEngine in Apache Servers

To enable the ReWriteEngine, add the following lines of code to the .htaccess file.

Options +FollowSymLinks
RewriteEngine on

These lines of code are only required once. You will then be ready to add your custom 301 redirects for any pages you wish.

How to Perform 301 Redirects

Redirect a single page to another:
Redirect 301 /retiredpage.html http://www.example.com/newpage.html

Redirect a whole directory to a new one:
RedirectMatch 301 ^/oldname/ http://www.example.com/newname/

Redirect a domain name URL to another:
RedirectMatch 301 ^(.*)$ http://www.xyz.com

Redirect several URLs to one canonical URL:
RewriteCond %{HTTP_HOST} ^xyz\.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*(default|index)\.(html|php|htm)\ HTTP/ [NC]
RewriteRule ^(([^/]+/)*)(default|main|index)\.(html|php|htm)$ http://www.example.com/$1 [L,R=301]

The above example uses the first two lines to redirect non-www. to www.

The second two lines of code redirect any URLs containing references to html/php/htm or default/main/index to the canonical home page URL without such references e.g. www.example.com/html, www.example.com/default will be redirected to www.example.com.

By performing this type of 301 redirect, you can consolidate several URLs into one page that receives all of the other pages’ rankings.

Once executed, the search engine will take some time to rediscover the redirect, recognize it and then pass on the link juice from the previous page.