How to: Enable HTTP Keep-Alive in WordPress?

No votes yet.
Please wait...

We usually enable HTTP keep-alive because it responses to header by keeping the client/server connection open across multiple server requests. The open connection improves the web performance when a client makes multiple server requests for webpage content, because the server can return the content for each request more quickly rather than processing all requests at once. Or if we don’t enable HTTP Keep-Alive, the server got to open a new connection for every single request.

HTTP Keep-alive

Locate the Code in .htaccess

To enable HTTP keep-alive response header in your WordPress blog all you have to do is to locate the following line codes in your blog’s .htaccess file. Or if you don’t know how to edit .htaccess file in WordPress, click here.

<IfModule mod_headers.c>
Header set Connection keep-alive
</IfModule>

Make sure you have place the above codes after line #END WordPress. Yep, you did it.

Similar Posts

63 Comments

  1. Nice article. Its rare to find a post that explains the use of KeepAlive from a practical yet conversational perspective. Most sites just regurgitate whats already said on the apache site. Thanks.

    No votes yet.
    Please wait...
    1. Well, thanks for stopping by @Taicmc. Keep visiting us for more helpful stuff…

      No votes yet.
      Please wait...
      1. Thanks buddy for this useful post, actually my website was suffering with slow speed issue and here you made it easy to fix. Thanks once more.

        No votes yet.
        Please wait...
  2. Hi Muhammad, thanks so much for this, just what i needed! My GTmetrix score went from 79 to 92 page load speed.
    Cheers.

    No votes yet.
    Please wait...
    1. Your welcome @Julian brother. It’s my pleasure.

      No votes yet.
      Please wait...
  3. Thank you for this useful tutorial. It work on my blog
    Previously my blog score on GTMETRIX is 97. Now the score is 99 on every single page 😀

    No votes yet.
    Please wait...
  4. Thanks mate. My score now in google is 95 🙂

    No votes yet.
    Please wait...
    1. That’s my pleasure @Sandeep brother.

      No votes yet.
      Please wait...
  5. Thanks for the code.

    No votes yet.
    Please wait...
    1. Hey @Plum, hope the code helped. By the way I thank you for stopping by and leaving positive comment.

      No votes yet.
      Please wait...
  6. Thank you, I managed to satisfy

    No votes yet.
    Please wait...
    1. It’s fine @ kursus mobil… Your welcome and keep reading my blog.

      No votes yet.
      Please wait...
  7. Thanks…..
    This working..
    my http://www.4um.in site up to 94 % ….

    thanks Muhammad Haroon..

    No votes yet.
    Please wait...
    1. That’s my pleasure @Mohamed Rafi.

      No votes yet.
      Please wait...
  8. Hi,

    what if I have W3 Total Cache installed, would it still help to add these lines at the end? please let me know.

    No votes yet.
    Please wait...
    1. Hi @Anupam,

      Yeah, these line of codes will do there own work after all W3 Total Cache caches your blog in it’s own directions.

      Regards,
      Admin

      No votes yet.
      Please wait...
  9. Thanks. I needed this

    No votes yet.
    Please wait...
  10. Hi, this is my first comment on a blog ever!
    I just felt like I had to give you a huge THANK YOU for this! My GTmetrix score shot through the roof….so happy!

    No votes yet.
    Please wait...
  11. Brother haroon, can you provide me your email address? i have added this code to the .htaccess file but still facing the issue. GTmetrix shows that keep alive is not enabled. If you could help me out i would be indeed very much happy.

    No votes yet.
    Please wait...
    1. This is all I can help with this article or if you need premium service you will need to contact me. Or try this.

      No votes yet.
      Please wait...
  12. How to Make expiry for header?

    No votes yet.
    Please wait...
  13. In you Mohammad, I have discovered the tech person to help me in technical issues related to WordPress. All along I was looking for a way to enable keep alive in WordPress. I read lengthy articles which confused me even more. But when I landed on this article, I was glad to see a simple and well explained process of how to enable keep alive even with 3W Total Cache installed. Thank you for being a nice teacher.

    This has been a great achievement for me today. My GTmetrix score has increased from 81% to 92% (from B to A?). The Pingdom score has also increased to 92%.

    I still have other related issues to work on to improve further my website speed performance. I believe, I will get the answers right here at this site. I have sincerely appreciated. You have made my day. Thanks for this tutorial. Keep it up Mohammad! Bravo!

    No votes yet.
    Please wait...
    1. Well, you are right and you can get many articles related to other WordPress issues on my site that will definitely help you @Charles. Keep visiting us for more informative articles. Thanks

      No votes yet.
      Please wait...
  14. Dear Mohammed Bhai,

    Currently my code in .htaccess looks like this…

    # BEGIN W3TC CDN

    Header set Access-Control-Allow-Origin “*”

    # END W3TC CDN
    # BEGIN W3TC Browser Cache

    Can you please help.. What should I put in .htaccess file and exactly where… I am a bit confused..

    No votes yet.
    Please wait...
    1. Hi @Aashish bro,

      You only need to place the block of code from this article to the end of your .htaccess file, don’t be confused. And if you don’t know how to edit .htaccess file, click here.

      That’s all.

      No votes yet.
      Please wait...
      1. Muhammad Bhai … Thanks A Lot.. This worked like a Gem 🙂 .. And Wish you a Very Happy Ramzan Bhai 🙂

        No votes yet.
        Please wait...
  15. I saw this on the GTmetrix website so thought I’d check it out… It definitely worked. It seemed to improve my score by about 15%, thanks Muhammad 🙂

    No votes yet.
    Please wait...
  16. Thanks for the tutorial, I used it and my speed score went up from 78% to 84%!

    No votes yet.
    Please wait...
    1. You are welcome @William. Keep visiting us for more interesting and useful stuff.

      No votes yet.
      Please wait...
  17. Thanks for this helpful article! Your advice worked 🙂

    No votes yet.
    Please wait...
    1. No problem.

      No votes yet.
      Please wait...
  18. Just amazing enhances the performance ..! Very thanks ..!

    No votes yet.
    Please wait...
  19. Thank you for this little code

    No votes yet.
    Please wait...
    1. No problem.

      No votes yet.
      Please wait...
  20. Hello I am a real ht access newbie! This page is really helping though. .Can you just confirm do I place the line of code before or after # END WordPress?
    Thank you so much!

    No votes yet.
    Please wait...
    1. Just put the code after the # End WordPress:)

      No votes yet.
      Please wait...
  21. Thank you for this information. Btw, what captcha that you used for this comment captcha?

    No votes yet.
    Please wait...
    1. It’s “SI CAPTCHA Anti-Spam

      No votes yet.
      Please wait...
  22. If I have RewriteCond after my # END WordPress, do I put the above code before or after the multiple RewriteCond I have?

    No votes yet.
    Please wait...
    1. You can put either before or after but you have to put the code once (Don’t place it twice).

      No votes yet.
      Please wait...
  23. Much needed code who have wordpress powered website.

    thanks for sharing

    No votes yet.
    Please wait...
    1. Yep any time. 🙂

      No votes yet.
      Please wait...
  24. Wow!! Thanks for this code, my PageSpeed Score went from 74% to 92%!

    No votes yet.
    Please wait...
    1. No problem bro 🙂

      No votes yet.
      Please wait...
  25. This is it!!! Wow!
    GTmetrix: Got from PageSpeed Score 75 to 90!
    YSlow score: From 91 to 92.

    Thanks a lot!

    No votes yet.
    Please wait...
    1. Yep. That’s it. I know it is amazing. Thanks for stopping by.

      No votes yet.
      Please wait...
  26. You nailed it,

    Thank you

    No votes yet.
    Please wait...
  27. Hi!

    I just tried this but it doesn’t seem to work. Can’t really figure out the problem though. I put it at the end of my htaccess, using the Yoast SEO plugin’s file editor. Does this take a while to get noticed by gtmetrix or do you have a clue what else could be the problem?

    thanks a lot!

    No votes yet.
    Please wait...
  28. Hi Haroon,

    I am facing 500 internal server error after pasting .htaccess code.

    Can you please guide me.

    No votes yet.
    Please wait...
    1. That’s normal in WordPress when you edit htaccess in a wrong way. just check this out for original htaccess file of WordPress.

      No votes yet.
      Please wait...
  29. Hello I tried this and it didn’t work GTMetrix still scores it 0. What else can I do

    No votes yet.
    Please wait...
    1. Contact Web hosting to increase privileges

      No votes yet.
      Please wait...
  30. Hi,

    I added into .htaccess file . but it’s not working. can you please provide another way or something

    thanks

    No votes yet.
    Please wait...
  31. I’ve translated my website with WPML, now GTmetrix is telling me to add the keep-alive code into the htaccess. But it’s already in there and it does work for my base language, could you tell me why it’s not working on the secondary language?

    Thanks!

    No votes yet.
    Please wait...
    1. Then you should consult with your host because they might blocking stagging environment of the secondary language.

      No votes yet.
      Please wait...
  32. Hi there Muhammad. I made the changes that you laid out to help the pagespeed by using the keep alive code but i still have a very bad pagespeed, specifically for the keep alive section as indicated by gtmetrix.

    Does it take a while for the changes to actually be applied? or is there something else that i need to do? Thanks for your help

    No votes yet.
    Please wait...
    1. Well, ask your web hosting provider to enabled the feature because in many cases the hosting providers have this feature disabled in apache configuration.

      No votes yet.
      Please wait...
    2. GTmetrix advise not to add Keep-Alive to the .htaccess file as it gives out false information to browsers. If you down have access to http.conf there is nothing you can do.

      No votes yet.
      Please wait...
  33. Hello. I used this code a few days ago, but gtmetrix is telling me the same (F score for “Keep alive”). Can you help me, please? You can see the website by clicking on my name. Thank you. 🙂

    No votes yet.
    Please wait...
    1. You are more than welcome.

      No votes yet.
      Please wait...
  34. Hey Muhammad, thanks for this post. This error was coming up during speed test. I have put that entry in .htaccess and now the error has gone.

    No votes yet.
    Please wait...
  35. sir very good artical and thanks for this post.

    No votes yet.
    Please wait...
  36. Enabling Keep-Alive connections in Apache

    Apache enables Keep-Alive connections by default, however you can explicitly turn them on by adding the following line to your httpd.conf file.

    KeepAlive On

    Having said that, if your site is running on a shared host, you probably won’t have access to httpd.conf and will therefore have to live with whichever setting your hosting provider has chosen. Contrary to what some websites suggest, adding a Header set Connection keep-alive directive to your .htaccess file will not actually enable Keep-Alive connections, but it will send browsers misleading information about the server’s capabilities.

    Do not turn on Keep-Alive in the .htaccess file.

    No votes yet.
    Please wait...

Leave a Reply

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