301 Permanent Redirect With .htaccess
301 permanent redirect is the most important part in SEO as it preserves your search engine ranking. This tutorial is a continuation of the .htaccess configuration tutorial series. In this tutorial we will learn what is a 301 permanent redirect and how to configure your .htaccess file to achieve 301 permanent redirection.
What is 301 Permanent Redirect
301 is a html status code which defines that a webpage or web address has been moved permanently to a different location. That means 301 permanent redirection is used to indicate that a web address has been moved permanently to a different location. This 301 status code is returned by the server and should be used in the location header of the response. Below is a very good video by Matt Cuts on 301 redirection. The major benefit of implementing a 301 permanent redirect is that it retains all of your search engine rankings, so you will never loose your page rank.
Why Should You Use 301 Permanent Redirect
Now comes the real question why should you use a 301 permanent redirection on your website. So here are the circumstances where you should consider using a 301 permanent redirection on your website.
- You’ve moved your site to a new domain, and you want to make the transition as smooth as possible.
- People access your site through several different URLs. If, for example, your home page can be reached in multiple ways – for instance, http://example.com/home, http://home.example.com, or http://www.example.com – it’s a good idea to pick one of those URLs as your preferred (canonical) destination, and use 301 redirects to send traffic from the other URLs to your preferred URL.
- You’re merging two websites and want to make sure that links to outdated URLs are redirected to the correct pages.
- You want to retain all your search engine rankings after permanently moving to a new domain.
301 Permanent Redirect With .htaccess Configuration
Here are different scenarios for the .htaccess configuration to achieve a permanent redirection on your website.
Scenario 1: Moving a single webpage permanently to a new location:
Add the below configuration line to your .htaccess file to permanently redirect an old page to a new page:
redirect 301 /old/old.htm http://www.yourdomain.com/new.htm
Either: 1. Make sure that you create a new .htaccess file under the ‘old’ directory if it is not there. If the .htaccess file is already there then you can simply edit the file and add the above lines of code to it.
Or: 2. You can edit the .htaccess file present under the root directory and add the above lines of code.
Scenario 2: Moving your old domain to a new domain permanently:
If you are moving your old domain to a new domain then you should consider 301 redirection for the complete website. Below are the configuration code that you should add to the root level .htaccess file:
redirect 301 / http://www.yournewdomain.com/
The above code ensures that your old domain is permanently moved to the www.yournewdomain.com. So whatever rankings your old domain was having the same ranking will be transferred to the new domain. So that way you will be safe on the search results. I hope this tutorial was useful for you. There will be new tutorial coming soon on .htaccess file configurations.