What are .htaccess files?

If you were working with WordPress you probably noticed that the installation includes a .htaccess file in its main directory.

Whate are these files?

The .htaccess file set specific directives for the server that should be executed when an Apache server is handling requests. In the default case of WordPress it makes the server point most of the requests to the main index.php file, which then loads all the necessary scripts. The server needs to be configured to look for and honor the directives included there. That can be achieved using the AllowOverride directive that is specified by by directory. Access files allow you to set different directives per directory without the need to touch the main server configuration.


<Directory "/path/from/where/the/files/are/served">
    AllowOverride All

In this case the server will include all the directives that are premitted to be set there.

Other options are:

  • "None" - the server will not even look for .htaccess files
  • directive type - one or more of the directive groupings such as "AuthConfig" or "FileInfo"

The configuration is applied to the directory where the access file is found and all subdirectories. However, subdirectories might contain their own access file that override configuration from higher up, because it's being applied in the order that the files are found.

The default name of the access files is .htaccess, but this can be changes to something else using the AccessFileName directive:

AccessFileName ".config"