I would like to know what should I implement in my htaccess file for making my website faster and secure. What do you recommend me?

2 Answers 2


There is no such thing as "Perfect .htcaccess".

Each site and environment are different and have diverse needs. Having one htaccess that works for one site on one specific hosting, doesn't mean that it will work the same way on other sites on the same hosting, or on the same site on another hosting.

Lodder is right, that you should know what you are doing with the htaccess file, but I could say that is not that crucial, because if you do something that will put your site down you can just rename or delete the htaccess, and the site will be back again.

Although htaccess is very powerful, it's not destructive, so yes someone can experiment with it.

And indeed you can enhance both the security and the speed performance of your website through htaccess, but it's not the only thing you need to do.

Nicolas Dionysopoulos (the guy behind Akeeba backup and Admin Tools) provides a master htaccess file, a template that contains many essential rules which you can tweak to meet your needs.

You should go through and read each line of it and make use or change whatever meets your specific needs.

It can be found here: https://github.com/nikosdion/master-htaccess/blob/master/htaccess.txt

More about Speed Improvements:

Similar htaccess Question in JSE:
Joomla remove index.php - redirect to homepage .htaccess


In addition to @FFrewin's answer (I would also recommend @nikosdion's Master htaccess), you should explore the options in the html5boilerplate htaccess which provides many options for improving security and performance:


As previously noted by @FFrewin though you can't simply drop all of these rules into your htaccess and expect it to work. Apply rules that you think you need one by one and check after each that you didn't break your site.

If you have access to the server config then you should apply the rules there, instead of htaccess, as it wont slow down your site like a large htaccess file would. More details on that here:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.