How to speed up WordPress site using .htaccess

Every webmaster or blogger has one common goal and that is to speed up their blog as much as possible without sacrificing any existing element such as attractive theme, image or useful plugin. Nobody’s is denying the fact that looks, presentation or appearance also play important role in blogging. But in most of the cases, they are the prime reasons of a slow loading blog if not maintained sophisticatedly.

Here are the some dreadful effects a slow loading blog can cause us:

  • Negative user experience.
  • Lower conversation.
  • Drop of sales.
  • Getting penalized by Google and other search engines causing down slide in SERP. (Blog loading is one of the algorithm factors)



You may be thinking, despite having a well coded theme and a great web hosting, why am I still witnessing sluggish website performance in terms of loading?

Well, there could be plenty of small reasons behind it which combined together may be heating up your blog loading time. Some of them are strictly technical and critical steps need to be taken to get solved and some of them are really easy to fix. Let me give you a small practical instance to understand it better.

Suppose you scattered things in the middle of a room and you need to pick something which lays other part of the room. So you have to go there zigzag way to get that thing. If you had a clean room you could go there straight which would have certainly saved some precious moments.

Your website runs exactly the same way. At the beginning when your website is fresh you would be getting great performance. But when it starts getting old along with plenty of posts, revisions, images, theme alteration, and bulkier website database, it will naturally get slower and pain would be higher if they are untidy or scattered all over the place. When a visitor comes to your website, server has to solve several requests to serve what has been asked by the visitor. If you are looking for better site performance, you have to arrange things in order which will help your server to perform better.

Must read: How to Speed Up & Secure WordPress Blog With Fre CloudFlare CDN.

You got to take action to set up some rules which will automatically put things order. You need to perform some periodical maintenance processes such a database management, optimization of images, checking and clearing log errors etc. As of now, let me show you how to speed up WordPress site using .htaccess file. And if you want to drag your website loading time below 1 second, then read my extensive article: Ins and outs guide to reduce blog loading time.

Let me tell you beforehand, what you would be doing with .htaccess file. You have to include or modify some codes inside .htaccess file which could be found in your hosting account domain main root directory.  

Understanding .htaccess file. What is .htaccess?

A .htaccess (hypertext access) is one of the main critical configuration files which basically has the remote power to control directories or sub directories inside the same parent directory it is located.

Well, in layman’s word .htaccess is used for:

  • Rewriting URLs in website.
  • Create 301 Redirect.
  • Password protect directories.
  • Disabling hot linking.
  • Blocking the door for spammers.
  • Cache Control using apache server feature.

In this post I am only showing how to speed up WordPress site using .htaccess but you can take a look at my other post where I have explained what else you could do with .htaccess file.

How to speed up WordPress site using .htaccess:

I know most of you are already advance blogger and know how to handle cPanel but still I will start from right at the bottom with ‘how to locate .htaccess file in cPanle’. I made this small video in which I have shown every possible steps in details to speed up WordPress site using .htaccess.

Caution: Take a backup of your .htaccess file, so if anything goes wrong you can revert back to the original!

1# We will start with Gzip compression:

I guess you already know the concept of gzip and you may have already used this method compressing a large files into smaller ones. Here we will follow the same method and will give sever command to gzip or compress files before sending to visitors. By compressing we can significantly reduce the file size resulting lesser bandwidth use and better server performance.

We can see the example of my website; after being compressed 77.7% bandwidth was saved! Check your site bandwidth saving when gziped


It’s really easy to take the benefit of GZIP. Just place the below mention code before the ending of .htaccess file. If you are not sure exactly where to paste this code, please watch the above inserted video.

<ifModule mod_gzip.c>mod_gzip_on Yesmod_gzip_dechunk Yesmod_gzip_item_include file .(html?|txt|css|js|php|pl)$

mod_gzip_item_include handler ^cgi-script$

mod_gzip_item_include mime ^text/.*

mod_gzip_item_include mime ^application/x-javascript.*

mod_gzip_item_exclude mime ^image/.*

mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*


*** Note: If your website returns with 500 internal server error that means mod_gzip module is not enabled and you need to ask your web hosting service provider to enable that.
2# set Browser Caching and expiry headers:

When a visitor steps into your website browser has to fetch each and every file such as CSS styles, texts, script and images. Naturally server has to solve lot of requests but if we set some feature like Browser Caching and expiry headers it will be lot easier to present the database for the returning visitors. Besicallt this command gives instruction to browser to store some particular files for a specific stipulated period of time. So when a visitor comes back browser itself can present those files instead of sending them to server resulting quicker website loading. This is one of those critical elements you got to set for better website performance.

There are two codes you actually need to paste in your .htaccess file. One is, setting the expiry date limit for browsers, means till when browsers should hold back the cache data.

# BEGIN Cache-Control Headers<ifModule mod_headers.c><filesMatch “\.(ico|jpe?g|png|gif|swf)$”>Header set Cache-Control “public”


<filesMatch “\.(css)$”>

Header set Cache-Control “public”


<filesMatch “\.(js)$”>

Header set Cache-Control “private”


<filesMatch “\.(x?html?|php)$”>

Header set Cache-Control “private, must-revalidate”



# END Cache-Control Headers

And second is header expiry date limit.

# BEGIN Expire headers<ifModule mod_expires.c>ExpiresActive OnExpiresDefault “access plus 5 seconds”

ExpiresByType image/x-icon “access plus 2592000 seconds”

ExpiresByType image/jpeg “access plus 2592000 seconds”

ExpiresByType image/png “access plus 2592000 seconds”

ExpiresByType image/gif “access plus 2592000 seconds”

ExpiresByType application/x-shockwave-flash “access plus 2592000 seconds”

ExpiresByType text/css “access plus 604800 seconds”

ExpiresByType text/javascript “access plus 216000 seconds”

ExpiresByType application/javascript “access plus 216000 seconds”

ExpiresByType application/x-javascript “access plus 216000 seconds”

ExpiresByType text/html “access plus 600 seconds”

ExpiresByType application/xhtml+xml “access plus 600 seconds”


# END Expire headers


Over to you:

Blog loading time is very crucial matter for every blogger. Almost every one who is in WordPress platform use cache plugin like W3 total cache or Super cache to reduce blog loading time. But these plugin themselves take almost half of a second to load. So instead of using these plugins you can edit and add codes in .htacces files to avail speed benefit. By using above mentioned code you can significantly speed up WordPress site using .htaccess. Please let us know whether it actually worked for you or not.



Post By Saikat Hazra (27 Posts)

Hello friends, This is me Saikat, the co-founder of this blog. An investment consultant who eventually turned into a professional blogger. Feel free to connect me on Google+. You can follow my post on Twitter


  1. Somali K Chakrabarti December 28, 2014
    • Saikat Hazra December 30, 2014
    • Limit the number of post in home page 5-6. You have 8 at the moment. Post excerpts are too long as well. Give it a second thought if you can scarifies some words.
    • Instead of displaying full picture use Thumbnails.
    • Optimize Images before uploading.
    • Use cache plugin like W3 Total Cache.
    • Check if any plugin is slowing down your blog with P3 (Plugin Performance Profiler) if found guilty and not indispensable you should get rid of that plugin.
    • Delete all unused plugins and widgets.
    • Optimize WordPress database. Specially the post revisions.
    • Disable pingbacks and trackbacks.
    • There are some other purely technical tweak you can do but those are only advisable if you are good to play with codes.

      Well, I’ll be posting a new article ‘Ins and outs guide to reduce blog loading time’ probably tomorrow. You can check.

  • Arpit Roy December 29, 2014
    • Saikat Hazra December 30, 2014

    Leave a Reply

    Your email address will not be published. Required fields are marked *