Speed up your WordPress Blog using .htaccess

Blog loading speed is an essential part of SEO. If your site takes much time to load then your website will be penalizing by search engines. Google penalize slow sites by dropping 20% search traffic from Google search. Other search engine like Yahoo, Bing also penalize slow sites by dropping 15-20% search traffic. Here are some .htaccess tips and tricks which can help you in speeding up your blog.
You have to use these codes in your .htaccess file located in your hosting account root directory.

How To Improve Blog Loading Speed Using .htaccess

Note: Backup Your Current .htaccess File Before Editing.

1. Use below code to enable Cache of website static files like PHP, CSS, JS


ExpiresActive On

ExpiresByType image/jpg "access 1 year"

ExpiresByType image/jpeg "access 1 year"

ExpiresByType image/gif "access 1 year"

ExpiresByType image/png "access 1 year"

ExpiresByType text/css "access 1 month"

ExpiresByType application/pdf "access 1 month"

ExpiresByType text/x-javascript "access 1 month"

ExpiresByType application/x-shockwave-flash "access 1 month"

ExpiresByType image/x-icon "access 1 year"

ExpiresDefault "access 2 days"


2. Compress output using GZIP. This snippet code will compress all the css, js, html files before sending to clients browsers with GZip compression.

mod_gzip_on Yes

mod_gzip_dechunk Yes

mod_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.*

This works only if mod_gzip module is enabled in your Web Hosting Server.

3. Add following snippet if your Web Hosting Server provides mod_deflate support.

SetOutputFilter DEFLATE

SetEnvIfNoCase Request_URI 

.(?:gif|jpe?g|png)$ no-gzip dont-vary

SetEnvIfNoCase Request_URI 

.(?:exe|t?gz|zip|gz2|sit|rar)$ no-gzip dont-vary

4. If mod_deflate is not supported in your hosting server use this code.

<FilesMatch ".(txt|html|htm|php)">

php_value output_handler ob_gzhandler

Let me know whether these helped in minimizing your blog loading speed.

Also Read : Change Affiliate URL And Create Custom Link for WordPress

Was this article helpful?

Last Updated on

5 thoughts on “Speed up your WordPress Blog using .htaccess”

  1. When I first discovered that my site speed was only 14/100 I knew I had to do something and fast. I started researching and implemented a few plugins for WordPress. Then in adjusting settings my .htaccess file became a little corrupt and the plugin asked that I removed the extras. Well I had no idea what should be in there and what shouldn’t. So how the heck was I to remove the extras? Anyway I stumbled upon your site and then started to re-write slowly my .htaccess file. Now thankfully site speed has jumped tremendously. I’d like to thank you for providing code to insert. Great articles.

  2. Hi Istiak
    When I inserted the code at 3. into my .htaccess I got an Internal Server Error – site wouldn’t work.
    I removed and it came back online.

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top


Sign up below to get started:

Share via
Copy link
Powered by Social Snap