How to edit and optimize the .htaccess file

Published On: 8 de December de 2019

Optimize the .htaccess file to increase performance and web speed

 

The power optimizing the htaccess file is very important when it comes to improving SEO positioning and to considerably increase the performance of your website. Next we show a series of codes that you can include in the htaccess file of your server.

 

Use of GZIP (The Gzip module must be installed on your Apache server)

This code is used to compress the information on your website to reduce bandwidth consumption and facilitate the speed in loading your website files on the server, and consequently it will reduce the loading time of the website.

Copy to Clipboard

 

Use of DEFLATE (The Deflate module must be activated in your Apache server)

It is another code similar to the previous one that allows compressing the information of the web by means of the Deflate module from the Apache server. We recommend this option before Gzip , because Deflate is much more compatible with old versions of browsers and it is also a fairly fast compression.

Copy to Clipboard

 

Activate the Keep Alive resource

It allows maintaining open connections between the client and the server, taking advantage of its resources without having to waste them in order to open a new connection for each element of the web page each time the client connects. This translates into faster response speed when loading a web page.

Note: It is not recommended if you want to maximize the security level of the server against attacks by cybercriminals.

Copy to Clipboard

 

Specify a Cache duration value

The web cache allows us to save copies of the response data that a server sends to a client each time it connects to the web page for the first time, so the next time it connects, the data will be extracted from the Cache saved so you don’t have to request them from the server every time you connect to the web. This translates into a faster loading speed of the web the successive times that the client connects.

Copy to Clipboard

The data “Max-age” It is expressed in seconds, so in this example the cache is set to 7 days, which are the days during which the web information will be saved to show it to the client each time it connects. You can configure the cache to last more or less days, depending on what each one wants.

 

Prevent Hotlinking

This code is ideal to prevent other websites from showing images of your website from your own server. This happens when they use the same url of your image hosted on your server to be able to show it on another website without having previously saved it on their server. What causes you to consume bandwidth from your server in a totally inconsiderate and illegal way. Every time a user visits the web page where the images of your website appear, requests are being made to the server where the image is hosted, which in this case would be your server.

To prevent these cases, there is a solution that what it does is show an image in the place of the images “stolen” from your server. Therefore, it is recommended that this image be a kind of warning that says for example “Image owned by xxxxx” or some other warning that causes annoyance to those who are stealing bandwidth from your server, at the same time that it warns those who They see that warning that images that do not belong to that web server are being stolen from that web page.

Copy to Clipboard

It is recommended that the image you want to show is hosted on an external server, such as Imageshack or Tinypic so as not to consume the bandwidth of our server.

 

Block IP addresses by creating a blacklist

In this way you can combat SPAM by blocking IP addresses that have junk content or that carry out SPAM practices so that they cannot access your website.

Copy to Clipboard

* Replace the IP addresses in the example with the IPs you want to block. You can add all the lines you want with IPs to block.

 

Remove the slash “/” at the end of the URL

Many servers are configured to show a bar at the end of the URL (http://mysite.com/blog/), so this can affect the display of your site on Google if your page “http://mysitio.com/blog/” does not have the same content as “http://mysitio.com/blog” so this code causes all URLs on your site to be displayed without the trailing slash.

Copy to Clipboard

 

Create a redirect to a new domain

This would be useful in case you have moved all the content of your website to a new domain and you want the visitors who enter the old domain to be redirected to the new one automatically.

Copy to Clipboard

 

Create a custom 404 Error page

If you want the server to display your custom error page when a visitor accesses a site on your website that does not exist.

Copy to Clipboard

 

Instructions for editing the htaccess file

In most cases, the htaccess file is created in the root directory of your website. Otherwise you would have to create a blank one to be able to insert the codes that we have explained before.

  • Access the files on your server using FTP. You can use any FTP access software for this step, however we recommend the Filezilla for being one of the best we know. Find the htaccess file and placing the cursor on the file, press the right button and then the option “View / Edit”.
  • The text editor will open with the content of the htaccess file. Copy and paste the codes you want to use at the end of the file content. Remember to replace the code data with those corresponding to your website, before pasting them in your htaccess file.

* In case you do not have an htaccess file, you will have to create one and place it in the root directory of your website and then simply edit it with the codes that you want to use and that we have shown you previously. To create a new file, go to the root directory of your website through the Filezilla FTP software. Right-click with the pointer inside the root directory and select “Create new file.” You name this file “htaccess” without the quotes, and you give it to accept. Once the file is created, you can edit it.

Do you have a Prestashop online store and want to optimize your site to increase its performance and web speed?

At Liewebs we offer you a web and database optimization service. We guarantee an increase in web performance, loading speed, data processing and database queries. Also improve SEO with this service, notably increasing sales conversions and daily visits.

Artículos relacionados

Échale un vistazo a estos otros artículos relacionados