Hãy nhìn lại lối sống của bạn.

How to Increase WordPress Page Speed using Htaccess ?

0 18

- Advertisement -

In the article How to speed up WordPress site htaccess optimization we have instructed you on some ways to help speed up page loading for websites. Today we will guide some other very important ways to help you optimize the site.

Whether you are a developer or an ordinary internet user, almost all of us loves faster websites. This post is focused on how to Increase Page Speed using Htaccess (WordPress). You might already know that there are a lot of ways to increase speed of WordPress using Htaccess code. In the following article, I will walk you through five best Htaccess tricks to optimize website speed.

How to Increase Page Speed using Htaccess

First of all, let’s start with a list of Htaccess tricks to increase page speed, which I am going to cover in this post. The list I have compiled covers the major recommendations by most of the web developers in the world to increase WordPress website speed using Htaccess.

  • Compression – Gzip and DEFLET
  • Enable Keep Alive
  • Leverage Browser Caching
  • Disable Image Hotlinking
  • Activate mod_pagespeed
  • Enable LightSpeed Server Cache

As mentioned above, the Compression – Gzip and DEFLET, Enable Keep Alive, Leverage Browser items we have presented at How to speed up WordPress site htaccess optimization article. Here we guide only about Disable Image Hotlinking, Activate mod_pagespeed, and Enable LightSpeed Server Cache.

Disable Image Hotlinking

Another Htaccess trick on the list is related to your site images.

Did you ever notice that someone is using your images on their website by using your image link directly?

Hmmm, No? YES? Not Sure?

Anyway, it really does not matter, whether you have noticed or not. There are chances that spammers can use your image link on their websites. And because of this, every time when someone visits that webpage, images will be loaded from your server. This is known as Image Hotlinking.

How does this (Image Hotlinking) affect your server? Well, it will use your server resources and bandwidth, which leads towards the higher load on your server. And hence slow or poor performance.

You can disable Image Hotlinking and Speed up your WordPress website using Htaccess. Add the following code in Htaccess. And do not forget to replace sample.comwith your own domain name.

# TN – DISABLE IMAGE HOTLINKIING START RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?sample.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ – [NC,F,L]
# TN – DISABLE IMAGE HOTLINKIING END

Enable mod_pagespeed – Increase Page Speed using Htaccess

Furthermore, this Htaccess trick to increase page speed and to optimize your website is especially relevant and works well with Apache servers.

Mod_pagespeed module was developed by Google to increase page speed of websites. Nowadays, few Hosting Provider like GodaddySiteGround and DreamHost etc. supports mod_pagespeed module by default. However, you can have installed the same by using SSH on your control panel.

Mod_pagespeed can be enabled by adding the following code to the Htaccess file.

# TN – ENABLE MOD PAGESPEED START
# COMBINE CSS, COMPRESS IMAGES, REMOVE HTML WHITE SPACE AND COMMENTS
<IfModule pagespeed_module>
ModPagespeed on
ModPagespeedEnableFilters rewrite_css,combine_css
ModPagespeedEnableFilters recompress_images
ModPagespeedEnableFilters convert_png_to_jpeg,convert_jpeg_to_webp
ModPagespeedEnableFilters collapse_whitespace,remove_comments
</IfModule>
# TN – ENABLE MOD PAGESPEED END

You can customize your mod_pagespeed module by using customization options and filters available here.

LightSpeed Server Cache – Enable it

In addition to that, if you are using LiteSpeed Server to run your website like we used to use LightSpeed Server with A2Hosting. You should use the following Htaccess code to enable server level caching. This will increase your speed up your WordPress website significantly.

# TN – ENABLE LITESPEED CACHE START <IfModule LiteSpeed>
CacheEnable public
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^GET|HEAD$
RewriteCond %{HTTP_HOST} ^sample.com|sample.net|sample.org [NC]
RewriteCond %{REQUEST_URI} !login|admin|register|post|cron
RewriteCond %{QUERY_STRING} !nocache
RewriteRule .* - [E=Cache-Control:max-age=300]
</IfModule>
# TN – ENABLE LITESPEED CACHE END

Don’t forget to change sample.comwith your own domain name. If you don’t want to enable caching on multiple domains delete the hyphen (|) and other domains.

Wrapping It Up

Before concluding this post, I have a bonus tip for you.

You probably know that your website can be hacked by only revealing your server information. Hide Server Signature by adding this code to your Htaccess file.

# START – TN Disable server signature # ServerSignature Off
# END – TN Disable server signature #

As a result, after the implementation of these Htaccess tricks, you will notice a significant increase in page speed using Htaccess.

Finally, do check your website on Pingdom or GTmatrix and compare the results with baseline.

Does your website loads faster without using any caching plugin?  I am sure your answer would be a big YES!.

Share the percentage (%) change in your website loading time in the comments section below, or fire away your queries. I would be happy to help.

Read more How to speed up WordPress site – images optimization

- Advertisement -

Để lại bình luận

Địa chỉ email của bạn sẽ không được công bố.

Website này sử dụng Akismet để hạn chế spam. Tìm hiểu bình luận của bạn được duyệt như thế nào.