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

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.