Submit post
Go to Blog

Improve Page Load Times with Your .htaccess File

Chris Simmance
Improve Page Load Times with Your .htaccess File

Are you challenged by slow page load times? You can shorten the time it takes to load your page and possibly improve your Google search ranking by altering your .htaccess file.

What is an .htaccess file?

An .htaccess file is a file used on Apache webservers to configure the server software. This is done so that the server software behaves in particular ways to either enable or disable certain functions that server features. There are many uses for this file, such as redirecting URLs, rewriting URLs, protecting sensitive parts of a website or even blocking specific IP addresses.

Always take care when updating these files as even the smallest typing error could result in problems for the website. Errors could cause pages and functions on a website to become unavailable, or even make the entire website itself unreachable. Always backup the file and test the changes made to militate against any potential issues you may have unwittingly caused.

There are other server types out there so such as Nginx, Microsoft’s IIS and Google’s GWS. However, Apache has a larger share of sites using it currently, which is why I’ve decided to cover it in this post.

Why should you try and speed up your site’s page load times?

There are two very good reasons why you should try to improve your site’s page load times: user experience and improved search ranking.

User Experience Generally speaking, most users are not happy waiting excessively long for a page to load, especially if they are browsing multiple pages on the same site with the same wait times. It stands to reason that the faster a user’s browser can load a page, the better experience that user will have.

This can have an impact on your site’s sales, signups and repeat visits. Now more than ever, with users’ Internet speeds increasing, your page load speed will be more noticeable if it’s slow, and this could affect engagement and your bottom line.

Search Rankings There are a few reasons that a faster page speed can improve your site’s rankings both directly and indirectly:

  • Faster Crawling Speed If a search engine robot can crawl your site faster, it is more likely to crawl all of your pages and content without timing out. A slower crawl may mean vital pages or relevant content is missed, and thus the opportunity to rank higher is lost.
  • Google Loves It Google uses site speed in its ranking algorithm (and has since 2010), and this is one of the direct ways that a fast or slow load time can have an effect on your search engine rankings. Google are obsessed with speed, and this is reflected in them publicly stating that they are using it in their algorithm. This is even more important now with the increased number of mobile users over cellular networks.
  • Reduced Bounce Rates More of an indirect factor here, but if your site has a slow page load time you are more likely to have a higher bounce rate. Users go back to the search results in search of a faster site to get what they were after would count as a bounce, and this could hurt your search rankings.

How can you speed up a page load by using your .htaccess?

Below are a few quick ways that you can improve your load times with your .htaccess file. I definitely recommend backing up the original file and testing your site after each change before finalizing any update.

This will prevent any unintended issues that may come up on the site through errors or typos in the file edits.

GZIP Compression Simply put, compressing your files makes them smaller and quicker for them to be transferred and loaded. Directing your webserver to enable GZIP compression can be a great quick win when speeding up load times. To do this you need to add the following to your .htaccess file: GZIP

Once you’ve updated the file, you can test to see if it is working. This tool also shows by how much the files are being compressed. Enable Browser Caching When a browser reaches a page, it has to load several things that very rarely change, like certain style sheets and logos for example. By setting expiry headers for files on your site, you are effectively telling the browser to save them locally on the user’s computer. This means that the next time the user visits the site, less data needs to be downloaded.

Adding the code below to the top of your .htaccess file will tell browsers to save files for return visits:

Caching code

If your files change more regularly, you can update the code above to ‘1 week’ or remove a file type if you do not want it cached at all. Remember though that if you make changes to the pages in between a user visiting and the time you’ve set the cache to expire, they may not see the new version right away.

Enabling Keep Alive Enabling Keep Alive is basically a way for the webserver to tell the browser that it doesn’t need to make a separate request for each file it retrieves on a site. This cuts down the brief latency following a request for a resource and downloading it on the browser. Check here before adding the code below, as in many instances this could have been added by default on the webserver.

Enabling Keep Alive

Deny Spam Bots Access Sometimes a page load speed can be reduced by the bandwidth you have available on your hosting plan. This can be even further reduced if your site is sharing a server with others. The last thing you need then is for spam bots to take even more of your bandwidth away as they crawl your site for whatever reason they were created for (usually to mess up your analytics data)! There are two ways to do this; one is to block them and the other is to redirect them away, although this in itself could slow the site loading down.

Spambot code

There are a few other ways to improve a page load time that don’t need any changes to your webservers config files. A few of them are below:

  • Go for dedicated server web hosting
  • Pick a server in or as close to your target audience (not in Germany when you target the US for example)
  • Use a Content Delivery Network (CDN) to cache and serve resources faster
  • Minimise the amount of redirects on a page
  • Remove (where possible) query strings from static files/links
  • Compress images and where appropriate use CSS image sprites
  • Combine Java Script and CSS files where possible
  • Avoid unnecessary repetition of CSS

If you want to benchmark your site load times to see how much each of these .htaccess updates can speed things up you can try using tools.pingdom or gtmetrix for free.

Are there any other areas you can think of to improve page load times? Share them in the comments and help to improve the speed of the web!

Chris Simmance is the Founder of Optus Digital, a Digital Marketing Agency in London specializing in SEO, PPC and content marketing.
Share this post


2000 symbols remain

Either just recently joined or is too shy to say something.

It was really an amazing experience while going through your blog. I found the blog content very useful and informative, I am sure it will really help me a lot in making valuable comments on other blogs. Your work and passionate efforts are really appreciable as you are also being a mentor to all new bloggers empowering them to build a successful career in blogging. Thank you for these useful tips. I am waiting for your next blog, so I will get more knowledge and will read new things. I am web designer by profession. [ad removed by moderator]

Either just recently joined or is too shy to say something.

Great article Chris,

After reading your article i add clear browser cache code in .htacess file


ExpiresActive On
ExpiresByType image/jpg "access 1 month"
ExpiresByType image/jpeg "access 1 month"
ExpiresByType image/gif "access 1 month"
ExpiresByType image/png "access 1 month"
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "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 1 month"


After adding the above code site speed increased but when i posted new articles they are not updated automatically after click Ctrl + F5 only they showing in website.

please let me know how to fix this....

Either just recently joined or is too shy to say something.

Great post, Chris - agree with all. I do however have a particular delay tho and am wondering whether it is related to my .htaccess file.

In the waterfall in I am consistently getting a 1.25 second bar on the very first request - which I believe includes the time to construct the html 'box' for the page but also may include time to rewrite/redirect the URL. 1.06 seconds of this is just "waiting time". On other sites, I have seldom seen this particular request to be over 500ms. (We are on a virtual server with 3GB of memory. However, increases in php memory allocated to the site have had minimal effects.)

My .htaccess includes all elements you discuss above (except the spambot piece) as well as 373 redirects, 122 lines of expiry related code, and 15 mod rewrites for handling urls with queries in them -- as well as the normal WordPress code and a couple of rewrites for specific plugins.

Any chance this long delay could be related to the size & complexity of the .htaccess file?
Chris Simmance

An experienced member who is always happy to help.

Hi Glenn,

Sorry for the delay. I've been away.

What platform is the site on? If its on WP I recommend that you install the P3 Profiler Plugin and you'll soon see what plugins are making loads of SQL and PHP requests. Each time a plugin feature is loaded on a page the browser sends a request to the SQL database, each request slows the load down.

If you can, minimise plugins and where possible get their features hard coded in where possible.

Hope that helps,


Either just recently joined or is too shy to say something.

Hi Chris,

Just followed your advice re the htaccess file above and have had some great results! Page load reduced from 5.11 to 3.5 seconds! Not bad for 10 minutes work!

Bizarrely GTmetrix still reports many css and js files with 4 hour cache expiry times even though i've included them in the htaccess as above - any clues why that might be?

Thanks again, a great post!
Kathleen Garvin

Either just recently joined or is too shy to say something.

Tom Lever
Great to hear, Tom! I'm sure Chris will be happy as well :)
Chris Simmance

An experienced member who is always happy to help.

Tom Lever
That's great Tom! It's awesome how quickly you can improve page speed with these updates.
Re the expiry, maybe there is something in your file overwriting it? Or perhaps GTmetrix erroneously picked up the times....

Either just recently joined or is too shy to say something.

Does this work with Wordpress sites as well? Any issues with plugins or templates?
Chris Simmance

An experienced member who is always happy to help.

Hi Thomas,
These are server side changes so they shouldn't have any harmful effect on your WP site. W3Total Cache is a good plugin to manage caching on WP.

Check out for some on-page tips too!
Adam Dince

Occasionally takes part in conversations.

Great post, Chris!
Chris Simmance

An experienced member who is always happy to help.

Adam Dince
Thanks Adam. Glad you liked it!
James Conway

Either just recently joined or is too shy to say something.

Thanks for sharing this data, Chris. I'm going to try some of this out and see if it helps my websites.
Chris Simmance

An experienced member who is always happy to help.

James Conway
Thanks James. I bet it will help! I'd be interested to find out how much you can improve the load times once you're done.

Send feedback

Your feedback must contain at least 3 words (10 characters).

We will only use this email to respond to you on your feedback. Privacy Policy

Thank you for your feedback!

Community Ranking System

Our SEMrush community rank reflects the level of your professional recognition in our community. We value quality contributions, so highly ranked members will get valuable incentives. Take part in discussions, write posts and speak on webinars, be friendly and helpful, and you will eventually get to the top of the ladder.

  • Newcomer
    Either just recently joined or is too shy to say something.
  • Enthusiast
    Occasionally takes part in conversations.
  • Helper
    An experienced member who is always happy to help.
  • Master
    A veteran community member.
  • Pro
    Asks great questions and provides brilliant answers.
  • Expert
    Provides valuable insights and adds depth to the conversation.
  • Guru
    A bearer of digital marketing wisdom.
  • Superstar
    Knows everything… well, almost.
  • Legend
    Getting here is not easy at all!