What is .htaccess?
It’s a directory level configuration file that can be placed in a directory to customize the configuration for different requests to the particular directory. .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.
Why It Starts With dot [.]?
This is because [.] files are by default hidden files on Unix and Unix like operating systems, and since it’s a configuration file so it must be hidden.
What Does It Do?
- It specifies the security restrictions for the particular directory.
- It helps showing custom error responses, i.e. 404 ‘Not Found’, 403 ‘Forbidden’ etc.
- Helps URL rewriting, i.e. you’ve a bad URL structure like www.site.com/rdgrt1?hym%+mobile%games, and you want it to be like www,site.com/mobile-games
- Helps the server to control User agent caching to reduce bandwidth usage
When To Use .htaccess?
If it’s a server with multiple users, i.e. a cheap shared hosting plan, users may want the ability to alter their site configuration. But remember that these users should not have access to the main server configuration files.
When Not To Use .htaccess?
If users have direct access to the server and you’re allowing individual users to modify the configuration, it may affect security.
Visit Apache.org to learn more on usage and application examples of .htaccess file.