The htaccess file or “hypertext access” as it is also known is vital for all websites, but it is one that can easily, and all-too-often, be overlooked.
Let’s look at some key points of the htaccess file
It’s important to know that the htaccess file will only affect the folder that it is placed in on your web server, and any subsequent folders. This is important to know when creating the rules within your htaccess file.
This is why it is handy to know that you can have more than 1 htaccess file – especially if you don’t want any specific rules to be applied to certain website folders.
The file will be loaded each time a URL is requested.
It is possible to add canonical tags to a non-HTML resource in the htaccess file.
I’ve talked a little bit about how larger sites, such as Trainline, use their htaccess in my case study, but its exact location can differ between CMS’ like WordPress.
There are 2 types of compression that can be applied to this file, that are not utilised as much as they perhaps could be.
The first is mod_gzip. This applies gzip compression which is a method for significant reduction of files. It works on Apache servers and is widely supported to ensure compatibility with older browser implementations. It can be applied as a static or dynamic module.
The second is mod_deflate. This is a faster mode of compression that gzip but it is also newer and is therefore not supported by all servers. It is for this reason that the former is the more widely used compression method. With mod_deflate, it allows the output from the server to be compressed before it is sent to the client over the network.
If you are having issues with the above methods, you can always check your GZIP compression using this tool: www.websiteplanet.com/webtools
The htaccess file is commonly used to redirect URLs, password protect some websites, display custom error pages such as 404 Error messages and to ensure consistency of the trailing slash on URLs.
But by remembering the above rules and compression methods we can unlock much more potential from this file.