3

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

4

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

3

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:

https://github.com/h5bp/html5-boilerplate/blob/master/dist/.htaccess

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:

https://github.com/h5bp/server-configs-apache

Your Answer

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

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