What Is an .htaccess File?
On servers that use Apache, an .htaccess file lets you control high-level website configuration without having to edit your server configuration files. You can even apply different settings to different directories by using multiple htaccess files. You can theoretically create an htaccess file in any directory on your server, either by directly creating a file via the htaccess command line or creating and uploading a plaintext file.
Generally, you want to minimize the number of htaccess files on your server because too many configurations can slow your server down. When your server sees an htaccess file in a directory, it looks for htaccess files in all the parent directories, too, increasing server resource usage.
Htaccess files that are higher up in the filepath always take precedence. If you want to make a configuration change to your whole server, we recommend editing the main Apache configuration files instead of adding an htaccess file in the root directory.
Apache is configured so all files named .htaccess are hidden. These files have important configuration information and could be used to compromise your server.
The most common uses for .htaccess are:
- redirecting URLs to be more easily readable (e.g., mysite.com/product/shirt instead of mysite.com/prodid=1234)
- loading custom error pages (e.g., 404 pages)
- forcing your site to use https instead of http.
- password protecting certain directories
- preventing hotlinking
Using htaccess files is a powerful tool for managing your server, but it can be tricky. Make sure you are familiar with making changes to your server via command line before you start editing htaccess files. Before making any changes to configuration files, we strongly recommend you take a backup of the file.
See the following articles for more information: