Select a topic:

Choose from one of the topics below to browse other articles

Articles & Information.

.htaccess basics

Last updated by Oleg C. on December 08, 2016 16:26

Introduction:

Hypertext Access, ordinarily abbreviated to .htaccess, is the Apache Web Server software configuration file intended for making configuration changes on a per-directory basis. A simple ASCII text file, containing respective configuration directives controls the directory it resides in as well as all sub-directories underneath it.

Using an .htaccess file you can:

  • Set a password to protect certain directories of your account
  • Set a hotlink protection
  • Create redirection rules
  • Rewrite URLs
  • Change default index file
  • Customize error pages for your web-sites
  • Enable SSI (Server-side includes)
  • Restrict access to your web-sites based on IP address/es
  • Prevent directory listing
  • Add MIME types

In the majority of cases you will not have to go through the .htaccess file editing since all the necessary directives will be added by the cPanel software automatically. For instance, when creating password protected directories, cPanel will do necessary changes to the .htaccess file for you.

Syntax:

.htaccess file syntax depends upon the Apache Web Server software version and slightly differs from one release to another. Thus, it's important to find out Apache version prior to make any changes to the configuration file.

How directives are applied:

Hypertext Transfer Protocol Daemon (httpd) looks for .htaccess configuration files in every single directory, causing .htaccess files to be loaded each time documents are requested. Configuration directives found in an .htaccess file are applied to the directory the file resides in as well as to all its sub-directories. However, it's important to remember that there may be .htaccess files in directories higher up. Directives are applied in the order that they are found. Therefore, an .htaccess file in a particular directory may override directives found in .htaccess files found higher up in the directory tree.

For instance: in the directory /home/joltsupport/public_html/ we have an .htaccess file containing the following directive:

Options FollowSymLinks

whilst in the directory /home/joltsupport/public_html/test_directory/ we have an .htaccess file with the following directives inside:

Options SymLinksIfOwnerMatch

Because of the second .htaccess file, Apache web server won't follow all symbolic links in the directory /home/joltsupport/public_html/test_directory/, as only Options SymLinksIfOwnerMatch is in effect, which completely overrides any earlier setting that may have been in place.

How an .htaccess file can be altered:

  1.  Please log into the cPanel control panel and enable hidden files displaying as it was described in another our article
  2. Click the .htaccess file (the file will be highlighted)

  3. Click the "Edit" button afterwards

  4. "Text Editor" window will pop up then

  5. Please scroll down to the bottom of the popped up window, click the "Toggle Help ..." link and read the provided information carefully

  6. Select the character encoding from the drop-down menu and click the "Edit" button