Hypertext Access file Setting up .htaccess


.htaccess files (or "distributed configuration files") provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.

An .htaccess file controls how Apache interacts with your site. It is used to alter the requests and modify default behavior without needing to alter the core server configuration files.

Setting up .htaccess is as simple as opening a notepad and saving it as .htaccess. Generally, this file will placed on the root directory of your website files, but you can use it under multiple different directories. This is especially useful if you're looking to password protect specific directories.

Enabling .htaccess

Sometimes even a single error in your httpd.conf or .htaccess file will result in a temporary meltdown of the server, and users will see 500 - Internal Server Error page. So, make sure to always make a backup of your httpd.conf and .htaccess files before you make a change.

<Directory "/var/www">
    AllowOverride All

.htaccess files are normally enabled by default. This is controlled by AllowOverride directive in the httpd.conf file. This directive can only be placed inside of a <Directory> section.

Beside All there are numerous other values that limit configuration of only certain contexts. Some of them are:

  • None - Completely disable .htaccess.
  • AuthConfig - Authorization directives such as those dealing with Basic Authentication.
  • FileInfo - Directives that deal with setting Headers, Error Documents, Cookies, URL Rewriting, and more.
  • Indexes - Default directory listing customizations.
  • Limit - Control access to pages in a number of different ways.
  • Options - Similar access to Indexes but includes even more values such as ExecCGI, FollowSymLinks, Includes and more.
# Only allow .htaccess files to override Authorization and Indexes
AllowOverride AuthConfig Indexes