When a visitor accesses your site, a HTTP request is made from the browser to the web server. Before acceding to this request, the server will check its configuration file if there are any directives to be applied. These directives include URL redirection, access control, IP blocking, etc. Once the directives are applied, the resultant page is served to the visitor.
As a site owner or administrator, you may want to fine tune the way visitors interact with your site. You may want add password protection to certain folders, prevent image hotlinking, block bad bots and rogue IPs, and much more. In most cases, especially where shared hosting is involved, you will not have access to your server’s configuration file. That is where .htaccess comes in. So what is the htaccess file all about and most importantly, what is relevance in the WordPress world?
htaccess is a configuration file that you can create and modify within your site to control various parameters. Using .htaccess, you can improve your site’s performance, boost its security and enhance its usability. It plays a significant role in preserving your site’s SEO rankings whenever URL redirection is involved. Some of the common features that you can enable/ disable with .htaccess are –
- Disable Server Signature
- Enable file caching
- Preserve bandwidth
- Disable AllowOverride
- Set default language and character set
- Enable URL redirection
- Enable Password Protection
- Prevent access to specific files
- Block certain bots and IPs
- Disable script execution
- Enable Custom Error Pages
- Set Default Index Pages
- Plan downtime by blocking access during certain time periods
The .htaccess file is especially important when you want to make configuration changes on a per-directory basis. Once you place an .htaccess file containing one or more directives in a particular directory, the directives will be applied to that directory and all the sub-directories within it. The .htaccess can be created and modified using any text editor and uploaded to your site using FTP.
An important point to note is that even a small error in the .htaccess file can cause lot big problems on your site. So you must always remember to backup your .htaccess file before making any changes to it. That way, even if something bad happens, you can revert back to a working copy of the file.