Have a Question?

If you have any question you can ask below or enter what you are looking for!

Understanding the Principles of .htaccess

Introduction:

Hypertext Access or the .htaccess refers to the Apache Web Server software configuration file designed to implement configuration changes on a per-directory basis. A simple ASCII text file that contains the configuration directives controls the directory including sub-directories under the main directory.

Through an .htaccess file you can:

  • Use a password to safeguard certain directories of your account.
  • Set a hotlink protection.
  • Create rules for redirection.
  • Rewrite Uniform Resource Locators.
  • Change the default index file.
  • Modify error pages for your websites.
  • Enable SSI.
  • Limit access to your websites based on IP addresses
  • Prevent directory listings
  • Add Multi-purpose Internet Mail Extensions (MIME) types.

Most of the time, you need not undergo the .htaccess file editing because the necessary directives are added by the cPanel software automatically. For example, in creating password protected directories, cPanel will perform the required changes to the .htaccess file for you.

Syntax:

The .htaccess file syntax depends on the Apache Web Server software version and slightly differs from other releases. It is essential to determine the Apache version before making changes to the configuration file.

Application of Directives:

Hypertext Transfer Protocol Daemon looks for .htaccess configuration files in each directory, loading .htaccess files every time documents are requested. Configuration directives found in an .htaccess file apply to the file directory and sub-directories. However, there may be .htaccess files in other directories higher up.

Directives are applied in the order these are found.

An .htaccess file in a particular directory may dominate directives found in .htaccess files in the upper portion of the directory.

For example, in the directory /home/joltsupport/public_html/, we have an .htaccess file containing this directive:

Options FollowSymLinks

Meanwhile, in the directory /home/joltsupport/public_html/test_directory/ there is an .htaccess file with the following directive:

Options SymLinksIfOwnerMatch

The second .htaccess file makes sure the Apache web server will not follow all symbolic links in the directory /home/joltsupport/public_html/test_directory/. Once Options SymLinksIfOwnerMatch is in effect, it completely overrides any previous setting.

Altering an .htaccess file:

  1. Log into the cPanel control panel and allow the hidden files to be displayed as described in another article
  2. Click the .htaccess file so it will be highlighted
  3. Click the “Edit” button
  4. Text Editor window will pop up
  5. Scroll down to the bottom of the popped up window. Click the Toggle Help link and read the information carefully.
  6. Choose character encoding from the drop-down menu and click “Edit” button.