10 Ways to Use .htaccess to Speed Up Your WordPress Site

How to Speed Up Your WordPress Blog Using .htaccessFast loading speed is one of the main factors for ranking quickly.  visitors can’t like a slow loading blog and website.

Some people think Google given rank fast loading website but it is false, Google penalized slow loading website.

Here I share with you best ways to use .htaccess to How to speed up your WordPress blog.


Before We Begin: Make a Backup

At first backup your WordPress site for 100% security. It is Best Practices for every blogger. than go to your cpanel -> WordPress sites root folder and find  .htaccess file and open it. and pest below code

1. Enable caching : pest below code for Enable 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"

2.gzip files : gzip allows you to compress files, so obviously that means they load faster. The code below will gzip html, text, css, js and php files:

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

3. Stop hotlinking : 

some time anouther user use your blog image link. for this reson can slow your website

#disable hotlinking of images with forbidden or custom image option RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com/.*$ [NC] #RewriteRule \.(gif|jpg)$ - [F] RewriteRule \.(gif|jpg)$ http://www.yourdomain.com/stophotlinking.jpg [R,L]

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

5. Use PHP compression

# php compression – use with caution <ifmodule mod_php4.c> php_value zlib.output_compression 16386 </ifmodule>

6. Stop spammers : This code Just like hotlinking, every time a spammer comes on to your site, they’re using your resources, so by stopping spammers you can free up said resources and speed up your site.

RewriteEngine On RewriteCond %{REQUEST_METHOD} POST RewriteCond %{REQUEST_URI} .wp-comments-post\.php* RewriteCond %{HTTP_REFERER} !.*yourblog.com.* [OR] RewriteCond %{HTTP_USER_AGENT} ^$ RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]

If you have any qustion and problem you can do this. If you liked this post, You can also discover us on facebook, twitter and-and Google+.

Arif Hossain

Hi, my name is Arif Hossain, I am a part-time blogger, and blogging is my hobby, I am a professional web designer. I share useful blogging tips to make bloggers' journey easier. I love to help newbie bloggers to build a better blog. You can connect with me on Facebook , Twitter , or Google+.Read more about me here.

Click Here to Leave a Comment Below 0 comments