Basic Things You Should Know About .htaccess

Many web hosting providers, offer access to a file called .htaccess – hypertext access. This “dot” file (the name begins with a “.”) when placed in a particular directory provides the ability for customization of the configuration of certain requests to that particular directory and it’s subdirectories. Following are the most common uses of the .htaccess file:

  • Rewriting URLs (aka Mode Rewrite)– is probably one of the most common uses of .htaccess file. Some blogging platforms and Content Management Systems by default produce URLs that may contain parameters in them, which are commonly referred as “ugly urls”. Implementing the mode-rewrite should not be attempted if you are not comfortable modifying the .htaccess. Platforms like WordPress or Joomle (as well as many others) provide either a reconfigured .htaccess file or allow modifying that file through the platforms interface.
  • Customization of the error responses. You can also use .htaccess to to customize which page should be shown to a visitor if a server side error occurs. For example you can tell your server to show a specific page if 404 Not Found error occurs by creating a custom “Not Found” page which can resemble the look and feel of the rest of your website and placing the following line into your .htaccess file:
    ErrorDocument 404 /Not-Found.html
    The above command will only work if the custom error page is placed in the root directory of your website (example: http://www.yourwebsite.com/Not-Found.html )
  • Redirects– another common use of .htaccess file is to implemen redirects. You can find more about 301 redirects, including non-Apache and Non-Linux servers here. One of the common redirects used by many web masters consist of following code in the .htaccess file:

    redirect /file.html http://www.somesite.com/
    The above command instructs to redirect a user to a specified URL.

  • Authorization and authentication. The .htaccess cna be often use to restrict the access to certain directories on your server. This is accomplished with an aid of .htpasswd file which is used to store valid user names and passwords needed to access a Basic Things You Should Know About .htaccessdirectory.
  • Cache (Cash :) ) control– allows you control user agent caching used by web browsers, which can reduce bandwidth usage and server load.

While .htaccess offers incredible flexibility in configuring your websites, it is also should be noted that use of this file can result in performance loss and may cause some security issues if not configured properly.

If you know of any other uses of .htaccess file, feel free to voice them in the comments.

Meet the Author

Vlad