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

## EXPIRES CACHING ##

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"

## EXPIRES CACHING ##

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

Sharing is Caring
Istiak Rayhan
 

Istiak Rayhan is the founder of RoadToBlogging.com, a blog that aims to make bloggers' journey easier. Istiak loves to help newbie bloggers to build a better blog. Here's more about him.

  • DRG says:

    Thanks :) Will check and let you know..

  • ankur says:

    that looking cool tommorow i check this and tell if its work for me or not..!!

    • Istiak Rayhan says:

      Yeah, Let me know.

  • Michael says:

    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.

  • 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.

  • >