Skip to content

301 redirect

November 13, 2011
By Administrator in All, Apache server

Knowing how to implement a 301 redirect has become a necessity for most webmasters or web developers nowadays. This article will show an easy way to create server-side 301 redirects on an Apache web server.

301 redirects are also known as permanent redirects and they are most commonly used when the webmaster decides to change the domain of their website. Using a 301 redirect ensures that both visitors and search engines would be able to access your website at its new location. This way, you will keep your visitors happy and you will retain any existing page rank and search engine results placement your website used to have. With a 301 redirect you can expect that most search engines would gradually “transfer” the page rank of your previous domain name to the new one. Using 301 redirects when changing the domain name of your website is strongly recommended by Google.

Note that 301 or permanent redirects should only be used if you really intend to permanently move your website to the new location. If the change is only temporary you have to use a 302 redirect, also known as a temporary redirect.

On the Apache web server, the famous mod_rewrite is used to implement the 301 redirect. The example below permanently redirects every page on to its new location on So, in order to implement a 301 redirect on an Apache server, you need to insert the following lines at the beginning of the .htaccess file in the folder containing your website:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^olddomain\.com$

RewriteRule ^(.*)$ "http\:\/\/www\.newdomain\.com\/$1" [R=301,L]

Needless to say, you need to replace and with the domain names you intend to use :). The example above permanently redirects both the main domain and the www subdomain to the new locations. If you only want to redirect one of the domains, you should remove one of the RewriteCond directives.

This should be all.

Tags: , , , ,

Comment Feed

No Responses (yet)

Some HTML is OK

or, reply to this post via trackback.