Forum Moderators: phranque
I've been puzzled for a while over this:
If, for example, I've got an .htaccess file in my root folder, which sets the DirectoryIndex and disallows image hot-linking.
I know that .htaccess files affect all sub-folders in the root folder. But what if I've got another .htaccess file in a sub-folder, which, say, sets the DirectoryIndex to a different index file.
Do I have to include the image hot-linking code in the sub-folder's htaccess file too, or does it automatically carry over?
And another thing..
I can have web-users and sub-domains on my site (using Plesk), does the .htaccess file in my root folder affect these too?
Since the webusers and subdomain directories aren't under my document root folder, I'm guessing I have to go into those directories (considered root for subdomains and webusers, right?) and put the file there? This is basically for disallowing hot-linking from these directories, so I'd just put whatever I had in my doc_root folder too, since the requests'd still be made to my domain ..
Am I right?
Thanks muchly for any help!
Alex ...
> I know that .htaccess files affect all sub-folders in the root folder. But what if I've got another .htaccess file in a sub-folder, which, say, sets the DirectoryIndex to a different index file.
Execution of directives in .htaccess is often referred to as "per-directory context." Any directive in a subdirectory that is traversed while the server locates the requested resource can override a directive in a higher-level directory -- .htaccess directives take effect on a per-directory basis. However, the italics above are intended to highlight that if a subdirectory is not traversed due to the action of a higher-level .htaccess directive, then the .htaccess in that subdirectory can have no effect.
So, in your specific example, the lower-level DirectoryIndex directive would override the higher-level settings.
> Do I have to include the image hot-linking code in the sub-folder's htaccess file too, or does it automatically carry over?
It will carry over as long as RewriteOptions inherit is set.
I can't directly answer your Plesk question, having no experience with it. But again, .htaccess directives only affect a directory and its subdirectories if the directory in which the .htaccess file resides is traversed while locating the requested resource. I suspect you'll have to place your anti-hotlink code in the effective root directory of each site.
A little testing will clarify all this.
Jim