Forum Moderators: phranque

Message Too Old, No Replies

where to put the htaccess

         

lucy24

8:38 pm on Jun 18, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I think there's a judgement-call aspect to this question, so I'm asking for opinions rather than simply pore over the Apache documentation.

Right now I've got my main htaccess in the default location, plus a couple of micro-htaccess files for a few specific directories to allow indexing or to point to a directory-specific error page. They all do what they're supposed to do. So I'm not asking "how" or "where" but "whether".

The question: most of my rewrites or redirects apply to things that happen within one subdirectory or another. (Think of it as half a dozen micro-sites under the umbrella of one mini-site. There's practically no cross-directory traffic, and very few cross-directory links.) Would it be a good idea to put these into local htaccess files within the relevant directory, instead of leaving everything in the master file? Pros and cons?

The obvious "pro" is that ::cough, cough:: there's less risk of bringing the whole site to a crashing halt if I misspell something.

I'm thinking mainly of redirects, but directory-specific blocking is a temptation too. ("I don't care what costume you're wearing, if you're from g### you're not getting in here and that's final!")

lucy24

5:54 pm on Jun 19, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Follow-up to the above (but the general question still stands):

Q.: When do you need to make a directory-specific .htaccess file?
A.: When it takes you months to figure out that the reason unwanted robots keep showing up in your /games/ directory is that the directory is aliased to your son's account so he can upload OS X ports without knowing your password, and therefore nothing you say in your own .htaccess has any effect on it.

Oops.

g1smd

7:17 pm on Jun 19, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



To be sure rules are processed in the correct order, if you have any internal rewrites in the root .htaccess, never put external redirects in the .htaccess within any of your sub-folders.

I tend to put all the rules in the root .htaccess file. If you have access to the server configuration you should add the rules instead to the main config file (and restart the server after that).

lucy24

9:23 pm on Jun 29, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Q.: When else is it to your advantage to maintain directory-specific .htaccess files?
A.: When you bring about untold chaos* by absent-mindedly overwriting your real .htaccess file (6K) with the tiny (60-odd bytes) .htaccess for an under-construction site that lives in the same neighborhood.

###.


* Where "chaos" is defined as robots with null user-agents asking for php files being served with a series of 404s instead of the 403s they were supposed to get, and an unknown number of search engines having to start counting all over again due to getting 404 instead of being redirected to the correct place or at least receiving an unequivocal 410.