Welcome to WebmasterWorld Guest from 54.196.233.239

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Trying to avoid redundancy in htaccess files

Stuck on some basics in core features & modules

     

Busynut

2:49 am on Jan 17, 2004 (gmt 0)

10+ Year Member



Hi all,
I'm trying to find out how to ensure my .htaccess files are written correctly and efficiently. I think I have some redundant directives in different folders but am getting stuck on some areas that I believe are pretty basic - I just can't seem to "get" it; and haven't found answers to what's stumping me. Here's some examples:

Files Directives
1. Can you have more than one directive within the same <Files></Files> section? e.g. can I deny my .htaccess files from everyone and then on the next line deny *.gif files from specific domains? Is something like this allowed?

<Files .htaccess>
order allow,deny
deny from all

*.gif¦jpg
order deny,allow
deny from baddomain.net
</Files>

2.a. I have a couple .htaccess files in different folders which do different things. My primary htaccess file denies access to the htacess file itself. Do I have to repeat this particular <Files> directive in each separate htaccess file or does the top directive protect the htaccess files in lower directories, too?

2.b. Same question about repeating these directives other folders --
-- Options +FollowSymlinks
-- IndexIgnore *
-- RewriteEngine on

Before you refer me to apache.org/docs/ - I've repeatedly read everything I can find on these directives - and don't see answers to these types of questions. Same is true for dozens of tutorial pages I've searched; maybe I'm just not 'seeing' answers that are there. I hope this makes sense? If you have suggestions for more reading material I'll gladly accept it. Thanks in advance for any help!

P.S. I'm on a shared server and don't have access to server config files.

jdMorgan

3:16 am on Jan 17, 2004 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



BusyNut,

1) No. You can have more than one directive, but they only apply to the file prefixes given inside the <Files> directive itself - within the <>, that is. <Files> </Files> is the container, and it contains other directives to be applied to all files (regardless of subdirectory path) that match the given pattern.

2a) No. <Files> directives apply to all files which match the given prefix in the current directory and all of its dependent subdirectories.

Note that this <Files> behaviour differs from that of mod_rewrite, which works with URLs. Since mod_rewrite uses URLs, the entire filepath is taken into account. But <FIles> just works with the filesystem, using the name of the file(s), and doesn't care if it is (they are) in the current directory or in a subdirectory, or both.

The transition from working with URLs to working with filepaths is subtle. Most webmasters don't even make the distinction until they begin to work with mod_rewrite. The distinction only becomes obvious when you realize that you can use mod_rewrite to re-map everything so that your filenames and your URLs no longer need to have anything in common. (Not that you should, but you can). Mod_rewrite takes URLs as input and outputs (usually) filepaths. So it exists in both worlds - the URL-world and the filesystem-world. Mod_rewrite can be forced to output URLs instead of filepaths by using the [PT] flag; This is sometimes necessary so that other URL-to-filename converting modules can use mod_rewrite's output before content is served.

2b) Options and IndexIgnore, No (I think). RewriteEngine on, Yes -- needed in each .htaccess file.

There is something there at Apache.org about "inheritance" or something - it's been awhile since I dug through it. The general rule is that configuration directives apply to everyhing in a directory and all of its subdirectories, unless you override the higher-level configuration in the subdirectory. You can also disable this override-ability if needed. RewriteEngine on is not a configuration directive, it's a module-control directive, so it is different. (Hope that's clear) :o

Jim

Busynut

10:12 pm on Jan 17, 2004 (gmt 0)

10+ Year Member



wow - thank you Jim for such a comprehensive answer - it is most helpful. Your practical answers really hit home - the majority of tutorials I've been finding are too 'academic' in that they don't provide adequate real life examples.

So to sum up (1) - my directive for limiting viewing of htaccess files just needs to be in the top directory <Files> container, and if I want to limit *.gif files I should add a second container.

And thanks for the answer on the 'repetition' (inheritance) of various directives - now I even have a better word to use in my searches (inheritance) - I guess my searches would be more productive if I knew the right words to use. LOL. If you decide to hold an online class I'll be the first to sign up.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month