Directory-level configuration file found mostly on Apache web servers
The htaccess file is a supplemental configuration file used by Apache to modify the default configuration as it applies to the directory the htaccess file it in (as well as all the files and subdirectories in that directory).
You should avoid using .htaccess files completely if you have access to httpd main server config file. Using
.htaccess
files slows down your Apache http server. Any directive that you can include in a .htaccess file is better set in a Directory block, as it will have the same effect with better performance.
Source: Apache manual
The directives allowed in htaccess files are governed from the main Apache configuration files by means of the AllowOverride
directive.
The most common use is in conjunction with the mod_rewrite and security modules of the Apache webserver. Mod_rewrite allows URLs to be rewritten for scenarios such as the following:
- Shortcuts such as example.com/info to redirect to another page
- Redirects from old pages to new pages
- virtual directories (directories which actually appear elsewhere in the file system)
The most common security applications are:
- Password protection of directories and files
For more information see the mod_rewrite and aaa documentation.