301 redirect with .htaccess

05.04.2013 by Ilia Raiskin
SEO htaccess

Today, you're going to learn how to create a 301 redirection for URLs with or without www with the .htaccess file. This technique is used to prevent duplicate content. If you don't redirect your websites URLs correctly, a search engine will detect your site with www and without www as two different websites. (example.com and www.example.com). Since your website with www contains the same content as your website without www, search engines will evaluate these URLs as duplicate content, which could lead to a worse position in the search results etc. Without correct redirecting http://www.website.com and http://website.com are two different websites for a search engine. A good solution is to create a 301 redirect with the .htaccess file. In the following example we redirect the website-URL without www to the URL with www. This means that if you enter http://website.com in the browser it will automatically open http://www.website.com.

It is also possible to do it the other way around - from the URL with www to the URL without www.

About the author

Ilia Raiskin

Ilia Raiskin is a web designer, web developer, blogger and founder of Toolinfy.com.