Forum Moderators: phranque
So I would like to know what kinds of information other members put into their .htaccess files. And if there are several informations in one specific file, which order do you then put them in?
Do you have .htaccess files on several different levels for specific purposes or do you put all the informations in one file?
How do you edit them? One of my hosting companies have this wonderful file management with the option of showing hidden files so I can see and edit my .htaccess files in real time.
Have you learned any lessons about .htaccess the hard way by making disastrous mistakes?
The order is based on what makes sense for your site; code dependencies, code execution efficiency, and keeping the file organized are my priorities.
> Do you have .htaccess files on several different levels for specific purposes or do you put all the informations in one file?
Yes, but I personally prefer to keep most of it centralized for ease of maintenance. On my sites, certain default settings made in top-level .htaccess are overridden by settings in subdirectory .htaccess. An example would be cache-control settings; I set the expiration time on files in the 'gif images' subdirectory to a much longer time that the default setting made in the top-level file.
You have to trade off code execution efficiency against centralized administration. For example, you might want to move all the code that prevents image hotlinking into the 'images' subdirectory. I used to do that myself, but then I moved the code back to the top level because I expanded it to protect scripts and CSS files after having those exploited.
> How do you edit them? One of my hosting companies have this wonderful file management with the option of showing hidden files so I can see and edit my .htaccess files in real time.
I edit on my own computer and upload to the server, but again, this is a personal preference. I can see how having a 'real-time edit' capability on the server would greatly help code testing, though (always test new code in a test subdirectory if possible, not on the 'live' part of the site!)
If you do edit on the server, always create a backup before you edit anything, no matter how small.
> Have you learned any lessons about .htaccess the hard way by making disastrous mistakes?
Yes,
... And, if you discover some neat new trick, post it here! :)
Jim