Down and Dirty with .htaccess files

12 08 2010

The .htaccess file can play an important role in SEO and usability. The file is placed at the base level of your website within your ftp or hosting folder and can be edited through a text editor such as notepad.

There are many things that can be accomplished within this simple text file.  Some of them are:

Canonicalizing URLs. Canonicalizing your URLs will help eliminate duplicate content that will ding you in the mind of google.  There’s a few ways of doing this, but the easiest way is through your .htaccess file.  You can do this by adding this code snippet:

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^MYWEBSITE.COM [nc]
rewriterule ^(.*)$ http://www.MYWEBSITE.COM/$1 [r=301,l]

Setup a 404 Error Page. Setting up a custom 404 error page will allow you to redirect traffic back to your site if a visitor encounters an error. You can do this by simply adding this line of code and pointing it to your custom designed error page:

ErrorDocument 404 /MYERRORPAGE.html

Block a Bad Site. With this snippet you can block all redirects from a site that may be giving you unwanted or inappropriate traffic.  There have been occasions where international sites can actually parse your site and plagiarize your content.  Using this snippet can help prevent these things from happening:

RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} BADSITE\.com [NC]
RewriteRule .* – [F]

Push a different version of your site live. If you need to temporarily host a different version of your site, for instance if you want to setup some quick AB testing or have a special micro site for the holidays, you can do so easily by using this snippet and simply pointing to the new homepage:

DirectoryIndex FILENAME.html

Prevent Directory Listings of Files. For many large sites there are always some files that make it onto your server that you’d rather not have publicly accessible.  You can disable these with this snippet:

IndexIgnore *.zip *.txt

If you are having trouble implementing these or just wish to save some time, you can also check out this handy .htaccess generator.

There are many things that can be accomplished within this simple text file.  Some of them are:

1. Canonicalizing URLs. Canonicalizing your URLs will help eliminate duplicate content that will ding you in the mind of google.  There’s a few ways of doing this, but the easiest way is through your .htaccess file.  You can do this by adding this code snippet:

Options +FollowSymlinks

RewriteEngine on

rewritecond %{http_host} ^MYWEBSITE.COM [nc]

rewriterule ^(.*)$ http://www.MYWEBSITE.COM/$1 [r=301,l]

2. Setup a 404 Error Page. Setting up a custom 404 error page will allow you to redirect traffic back to your site if a visitor encounters an error. You can do this by simply adding this line of code and pointing it to your custom designed error page.

ErrorDocument 404 /MYERRORPAGE.html

3. Block a Bad Site. With this snippet you can block all redirects from a site that may be giving you unwanted or inappropriate traffic.  There have been occasions where international sites can actually parse your site and plagiarize your content.  Using this snippet can help prevent these things from happening.

RewriteEngine on

# Options +FollowSymlinks

RewriteCond %{HTTP_REFERER} BADSITE\.com [NC]

RewriteRule .* – [F]

4. Push a different version of your site live. If you need to temporarily host a different version of your site, for instance if you want to setup some quick AB testing or have a special micro site for the holidays, you can do so easily by using this snippet and simply pointing to the new homepage:

DirectoryIndex FILENAME.html
5.       Prevent Directory Listings of Files.  For many large sites there are always some files that make it onto your server that you'd rather not have publicly accessible.  You can disable these with this snippet:
IndexIgnore *.zip *.txt

If you are having trouble implementing these or just wish to save some time, you can also check out this handy .htaccess generator.

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: