How to implement 301 permanent redirect
How to implement 301 permanent redirect
A 301 redirect is the most efficient and seo-friendly method for redirecting webpages. This code instructs the search engines that a webpage / pages have permanently moved to a new location. With 301 redirect, you can safely redirect your old pages to new pages without the fear of losing your search engine rankings. Search engines responds to 301 redirect by dropping old pages and updating the urls with new pages.
What is a 301 redirect?
First, what 301 redirect is? A 301 redirect is the most efficient and seo-friendly method for redirecting webpages. This code instructs the search engines that a webpage / pages have permanently moved to a new location. With 301 redirect, you can safely redirect your old pages to new pages without the fear of losing your search engine rankings. Search engines responds to 301 redirect by dropping old pages and updating the urls with new pages.
What is a 302 redirect?
Another redirect is the 302, which is also called the temporary redirect and is generally used when the old page is temporarily moved to a new page / when a new page is temporarily required. This is not quite seo-friendly and there are chances of having duplicate content indexed by search engines.
What is a .htaccess file?
You implement the 301 redirect by creating a .htaccess file, which is located in the root directory of your website. Wikipedia defines .htaccess file as a directory-level configuration file supported by several web servers, that allows for decentralized management of web server configuration. The original purpose of .htaccess - reflected in its name - was to allow per-directory access control, by for example requiring a password to access the content. Nowadays however, the .htaccess files can override many other configuration settings including content type and character set, CGI handlers, etc.
How to implement the 301 Redirect
1. To create a .htaccess file, open notepad, name and save the file as .htaccess
2. If you already have a .htaccess file on your server, you can download it for editing.
3. Place this code in your .htaccess file:
redirect 301 /old/old.html http://www.sourcing2india.com/new.html
(# space should be there between old location and new location and also do not add “http://www. to the first part)
4. Save and upload the .htaccess file to the root folder of your server.
Once you have done the above, you can test by typing the old address that you have changed. You should be taken to the new page (location) immediately.
When the search engines update their results, they will drop the old pages and replace them with new ones. (as per the rules mentioned in your .htaccess file). The search engine spider doesn't actually read the .htaccess file, but recognizes the response from the server as valid.
How to redirect non www to www version of the website
To redirect non www to www version you have got mod_rewrite enabled on your server and put this in your .htaccess file:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]
or this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
How to redirect your .htm pages to .php pages
Got mod_rewrite enabled on your server and put this in your .htaccess file:
RewriteEngine on
RewriteBase /
RewriteRule (.*).htm$ /$1.php
301 redirect can also be implemented for the following:
1. If you want to redirect all files on your domain use this in your .htaccess file, if you are on a unix web server:
redirectMatch 301 ^(.*)$ http://www.domain.com
redirectMatch permanent ^(.*)$ http://www.domain.com
You can also use one of these in your .htaccess file:
redirect 301 /index.html http://www.domain.com/index.html
redirect permanent /index.html http://www.domain.com/index.html
redirectpermanent /index.html http://www.domain.com/index.html
This will redirect "index.html" to another domain using a 301-Moved permanently redirect.
- categories:
