Increase WordPress Speed Using .htaccess

Increase WordPress Speed Using .htaccess

Speed is a what makes your website more usable, optimized for conversions, more enjoyable to browse and loved by search engine algorithms.

.htaccess is a configuration file, usually found in the root of your web domain, that can increase your website security, but also significantly increase WordPress speed.

Gzip File Compression

Compressed files result in a reduced HTTP response times. Gzip compression zips your HTML documents, scripts and stylesheets. Note that images and PDF files are already optimized and crunched and should not be further compressed.

With file compression you save server bandwidth and decrease amount of time for browser to download the files.

Apache servers

mod_pagespeed is an Apache module developed by Google. It automatically applies web performance best practices and you should always check with your hosting company whether it supports it. While at it, ask them to assist you install and configure it. Once installed you can copy/paste the code below, to your .htaccess file.

<IfModule pagespeed_module>
ModPagespeed on

I know GoDaddy, DreamHost, EdgeCast, SiteGround and MediaTemple (not on their shared hosting plans) support the mod_pagespeed module, so if you’re with them, you can just insert the code to your .htaccess.

If your hosting company doesn’t support the mod_pagespeed module, then you can use themod_deflate module. Just copy and paste the following piece of code to your .htaccess file.

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/css text/javascript application/javascript application/x-javascript

Nginx servers

If your host uses Nginx servers, to enable gzip compression you need this code in your .htaccess

server {
gzip on;
gzip_types text/html text/css application/x-javascript text/plain text/xml image/x-icon;

Browser Caching

By setting browser caching you’re telling browsers to keep particular files for a specified period of time. When the file is needed again, the browser will pull from its local cache instead of requesting it from the server again.

Browser caching saves a lot of your bandwidth. A first-time visitor will make several HTTP requests to download all your website’s files, but by using the Expires and Cache-Control headers you can make those files cacheable. This avoids unnecessary HTTP requests on subsequent page views.

Apache Servers

It’s done through the mod_expires and mod_headers modules.

These rules go to .htaccess for setting Expires headers:

# BEGIN Expire headers
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 5 seconds"
ExpiresByType image/x-icon "access plus 2500000 seconds"
ExpiresByType image/jpeg "access plus 2500000 seconds"
ExpiresByType image/png "access plus 2500000 seconds"
ExpiresByType image/gif "access plus 2500000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2500000 seconds"
ExpiresByType text/css "access plus 600000 seconds"
ExpiresByType text/javascript "access plus 200000 seconds"
ExpiresByType application/javascript "access plus 200000 seconds"
ExpiresByType application/x-javascript "access plus 200000 seconds"
ExpiresByType text/html "access plus 600 seconds"
ExpiresByType application/xhtml+xml "access plus 600 seconds"
# END Expire headers

and these are the .htaccess rules for setting up Cache-control header:

# 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

Max-age directive is not necessary for Cache-Control header because it’s already set by the mod_expires module.

Nginx Servers

For Nginx this would be:

location ~* \.(jpg|png|gif|jpeg|css|js)$ {
expires 50h;

MySQL Database Size

WordPress 2.6 brought several improvements, autosave being one of them. Revisions of your posts and pages are being created while you type and this increases MySQL Database. The bigger the database, the higher the response time. You can either disable the revisions feature alltogether by inserting the following code snippet in your wp-config.php:

define('WP_POST_REVISIONS', false );

or by installing a plugin called Optimize Database after Deleting Revisions and setting a limit on allowed revisions per post.

Whichever you choose to do you’ll definitely feel the difference in WordPress speed.

There’s lots one can do to increase WordPress speed, using CDNs (content delivery networks) orapplying performance best practices and using .htaccess is just one of many methods.

If you know and use other ways to speed up your WordPress website, use the comment area below and let us know.

Loading Facebook Comments ...

5 Comments. Leave new

March 28, 2015 9:36 am

Hi, i think that i saw you visited my weblog so i came to “return the favor”.I’m trying to find things to improve my site!I suppose its ok to use
some of your ideas!!

Tammy Hannon
March 30, 2015 3:46 am

This is my first time go to see at here and i am in fact impressed to read
everthing at single place.

April 10, 2015 4:31 pm

I’m now not positive the place you are getting your information, but good topic.
I must spend some time finding out more or understanding more.
Thanks for fantastic info I was on the lookout for this information for my mission.


I see many blogs outrank your website in google’s search
results. You should build more contextual backlinks.
These type of backlinks are the best after all these google algorithm updates.
Writing articles is hard work, but i know what tool
will save you a lot of time. This tool can also make you money, just search in google for:

Haough’s Essential Tool

May 6, 2015 12:36 pm

It is in reality a nice and useful piece of info. I am satisfied that you simply shared this helpful info with us.
Please stay us informed like this. Thank you for sharing.


Leave a Reply

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

Enter the captcha code * Time limit is exhausted. Please reload the CAPTCHA.

we have updated our price to free for all the product. Dismiss