Site   Web

June 29, 2010

Why You Need A .htaccess File For SEO

There are a good chance that you are wondering what the topic of SEO has to do with the .htaccess file.

In fact, it plays quite an important role in the way your website is ranked by the search engines. The problem is that few people are aware of its importance and it could be affecting the ranking of your website right at this moment.

What Is A .htaccess File?

According to Wikipedia, a .htaccess file is “the default name of a directory-level configuration file that allows for decentralized management of web server configuration.” If you’re not a computer whiz (and I’m not), such a definition is simply impossible to understand. So putting aside all the computer programming terminology, a .htaccess file is a tiny file which is placed within a website to do a number of functions.

This article will only cover 2 of these functions (there are many others) because they are only ones related to the topic of SEO. I will also show you how to write the .htaccess file so that you use your .htaccess file for maximum SEO effect.

Blocking Users

A .htaccess file can be used to allow and block users by domain or IP address. You would want to do such a thing because there are several online tools which people use to get the keywords that their competitors are using. This will then allow them to target your keywords and potentially push you down the search rankings. For example, one such tool is SpyFu. They literally allow you to spy on your competitors. If you want stop such tools from being used on your website by your competitors, then simply structure your .htaccess file like the example at the bottom of this article.

Redirecting URLs

If you did a search on Google and looked through the search results, you will find that some websites are indexed with www. in front of them and others without it. If you searched a bit deeper, you will probably find some websites indexed twice, once with the www. in front of them and others without it. Why is this the case?

This is due to backlinks being built to both the www. and the non-www. but the search engine treats them as separate websites. This means that you are creating links to 2 separate websites instead of just one. As a result, any SEO benefit is getting divided up between 2 websites when they could helping just one and getting much better results. If you want to avoid such a problem, all you need to do is redirect one URL to the other. It is best to redirect the URL with the least amount of backlinks to the one with the most amount of backlinks.

.htaccess File Example

Below is the .htaccess file I use for the great majority of my websites. It blocks access to the biggest and well-known spying tools on the Web as well as redirects a non-www. URL to a www. URL. Modify the code slightly by replacing “yourdomain” with your URL.

Simply copy the code, paste it in a notepad file and then save it as .htaccess. Then upload it using ftp or other means to your website.

Options +FollowSymLinks

RewriteEngine on

order allow,deny

deny from all

order allow,deny

deny from

deny from

deny from

deny from 66.34.0.

deny from 66.34.255.

deny from

deny from

deny from

deny from

deny from

deny from

deny from

allow from all

RewriteCond %{HTTP_REFERER} [NC,OR]

RewriteCond %{HTTP_REFERER} [NC,OR]

RewriteCond %{HTTP_REFERER}

RewriteCond %{HTTP_REFERER} [NC,OR]

RewriteCond %{HTTP_REFERER} [NC,OR]

RewriteCond %{HTTP_REFERER} [NC,OR]

RewriteCond %{HTTP_REFERER} [NC,OR]

RewriteRule .* – [F]

RewriteEngine on

RewriteCond %{HTTP_HOST} ^([a-z.]+)?$ [NC]

RewriteCond %{HTTP_HOST} !^www. [NC]

RewriteRule .?{REQUEST_URI} [R=301,L]

It’s amazing how a little bit of code can make a big difference to your SEO efforts.

Just in case you’re wondering, this is the only time that I will make reference to programming code when talking about SEO. The role of the .htaccess file was far too important to ignore and not share with all of you.

Martin Sejas is a highly regarded search engine marketing consultant based in Sydney with considerable experience and knowledge about how to improve website rankings. Register for a free consultation.

9 Responses to “Why You Need A .htaccess File For SEO

    avatar Debbie Shelor says:

    Hi – I appreciate knowing more about this file. Mine was causing problems with one of the blogs I put up recently. I had previously had a different blog at that domain and decided to move it. It left some files in the root directory and .htaccess file caused problems when I put up a new blog where the old one had been.

    I have also heard that because Google looks at the two sites – www and without – as separate sites, you can get in trouble for duplicate content if you don’t do a proper redirect in some way – the .htaccess file being one.

    Oh Sejas, what a great news for the day. We are happy to listen this news today. We are following this uploading .htaccess file with allmost every site. But how to know whether our competitors are visiting our site and are they copying the keywords, descriptions from our site or not. Is there any tool available to check this information. If you have that tool please let me give reply..

    Expert Web Developers in India
    Unified Technology Solutions
    Secunderabad – Hyderabad

    Thanks Martin for giving the brief information about .htaccess files in SEO

    avatar B2B China says:

    I’d like to use the .htaccess to redirect the URLs, as www. and non www. .htaccess is pretty cool to do all things like you said above.

    avatar Shafiq Khan says:

    Some useful info here, especially on blocking the spying tools, didnt know that was possible!

    avatar Naveen says:

    This is good information about the different purposes for which the file is used. I have essentially been a writer but developed a strong learning inclination for SEO. This post helped me a good deal in knowing not only what can be done from .htaccess but also how to do it?

    avatar Jay says:

    Dude, this is amazing information shared in such a easy language for newbiee…Thanks

    avatar digiclay says:

    hello friend, this is amazing information shared in such a easy language for newbiee… Thank you so much!!

    avatar Vishal Singh says:

    Thanks Martin i have read many tutorials for .htaccess file and i was yet confused about this but after read here i am satisfied thanks a lot again for sharing useful information.

Submit a Comment

Your email address will not be published. Required fields are marked *

Please leave these two fields as-is:

Protected by Invisible Defender. Showed 403 to 6,663,108 bad guys.