Skip to Main Content

What is an HTACCESS file and why do I need it?

Posted on 4.09.2006

HTACCESS stands for Hypertext Access. HTACCESS is the default directory level configuration file for Apache, which allows for custom configurations and commands.

Common uses for this file are redirects, URL rewriting, and to block access to certain files.

If you update your website and rename pages, you may want to redirect the search engine traffic and your visitor’s bookmarks to the correct new page names or URL’s.

First check the file manager program on your server to see if the .htaccess file already exists. Many servers hide this file from most FTP (file transfer protocol) software programs, so that is why I recommend trying the file manager on the server. If you are not sure, please contact your web hosting company first because it could cause problems with your Web hosting or other server software if you overwrite the existing .htaccess file.

Note: The file must be saved as .htaccess. (Not htaccess.txt or htaccess.html)

Here is an example of a 301 permanent redirect from an old page to a new page:

redirect 301 outdatedpage.html

Here is an example of how to make a redirect to a custom 404 error page, which is where the visitors are redirected when a page is not found:

ErrorDocument 404

Here is the most important of all redirects that you may want to consider using on your website. Many search engines are confused by the difference between the WWW version and a non-WWW version of a website, and sometimes index both which may cause duplicate content issues with the search results. Duplicate content can negatively affect your website’s search engine placement in the search results.

The following example will force a 301 redirect from the non-WWW version of your website to the WWW version of your website.

RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*)$1 [R=301,L]

Try visiting both and to test this redirect and see it in action. As you will see both links take you to the WWW version of the website.

Bret Fencl, Fencl Web Design.Com, LLC

Today's Top Picks for Our Readers:
Recommended by Recommended by NetLine

Leave Your Comment

Login to Comment

Become a Member

Not already a part of our community?
Sign up to participate in the discussion. It's free and quick.

Sign Up


Leave a comment
    Load more comments
    New code