Modifying the content of the .htaccess file is the fastest and most efficient way to increase the loading speed of the web, and improve the Natural Positioning in all search engines. This is not intended to be a manual on how to use htaccess.
I will simply indicate the codes that must be included, so that the performance of the page increases in a remarkable way, to improve the position in the search engines. Google uses loading speed as a ranking variable.
The .htaccess (acronym for HyperText Access) is a file that is placed in the root of your website (provided you use an Apache server), which contains certain information about how to access files. Of the wide range of possibilities it allows us, today we will focus on those that improve the loading speed:
Take a look of Cache
With this we make that people who have already visited our page and return to it, do not download again all the files, but use the ones they already have in cache (saved in their computer). It should be used in multimedia files, scripts, and style sheets. The code is as follows:
Header set Cache-Control “public”
Header set Expires “Thu, 15 Apr 2027 20:00:00 GMT”
With the “FilesMatch” directive we are telling to which file types (according to their extension) the cache should be applied. And with the “Header” directive we indicate the Cache-Control as “public” so that it allows to cache the file publicly, and the “Expires”, which indicates the date in which the cache ends. I prefer to use the “Expires” before the “max-age” because I have seen that it does not fail in any platform, on the other hand the “max-age” has problems in some versions of Internet Explorer.
This is a little tip I give you about web caching although personally I don’t use this code very much. There are cache plugins that solve these problems.
The idea is simple: It is faster to compress a file, send it, and decompress it, than to send it directly uncompressed. Although the process is more complex, it is much faster, since the compressed information that is sent takes up much less. The code is as follows:
Again, with the “FilesMatch” directive we tell it which files should be compressed, and with the SetOutputFilter directive we tell it to compress the files with the DEFLATE mod, which is the most widespread. If we wanted to compress everything, we would simply delete the “FilesMatch” directive and leave only the second line.
Etags are a tag or code that is assigned to each file. The idea is that it will be bought if the Etag of the file in the browser cache matches the one on the server. If it does, the file is not downloaded. The problem with Etags is that they are defined with unique attributes for each server, and many times they do not match, forcing the file to be downloaded even if it is already in cache. Here is the code:
Header unset ETag
En este caso no las colocamos en una directiva “FilesMatch”, porque queremos que se anulen en todos y cada uno de los tipos de archivos, sean los que sean.
Disabling the Etags and the LastModified we totally eliminate the If-None-Match and If-Modified-Since requests, and we save the 304 Not Modified responses, so the content will remain in Caché until the Expires that we have said in point 1 tells us that it is already available.
Header unset Last-Modified
This command can also be included in section number 1, within the “FilesMatch” directive to save a few lines of code, since they are the same type of files. It is important not to place HTM, HTML and PHP files there, as the content in these is much more dynamic, and updated more frequently. That is why we only leave Last-Modified. You can use all of these tips at the same time if we want to. This will give us a little boost to increase the loading speed of our website. However, you can also see more posts we have written to improve web security, also by writing code in the htaccess.