Forum Moderators: phranque

Message Too Old, No Replies

htacess effects on sub folders

         

Dell Hershwtized

12:53 pm on Nov 20, 2006 (gmt 0)

10+ Year Member



I have a questions

==> Is there any option I can set with to make a .htaccess valid for 1 folder only, and not the subfolders?

I dodnt want to set htacess for each and every folder and also if someone knows about RewriteOptions , then do tell me how it will work.

Thanks in advance.

jdMorgan

2:44 pm on Nov 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's not a simple question to answer without specific examples of the problem, but directives in an .htaccess file apply to the directory in which the .htaccess file resides and to all subdirectories of that directory by default.

RewriteOptions inherit or RewriteOptions none can be used to enable or disable (respectively) this behaviour for mod_rewrite directives only.

In general, if you find that all subdirectories of a directory in which you have .htaccess code need to be exempted from all or most of that code, then it is often simpler to re-arrange your directory structure so that those subdirectories no longer fall under the directory containing the code which you do not wish to apply to them.

With mod_rewrite rules specifically, you can write the rules so that they do not apply to the subdirectories of the current directory, but most other modules' directives do not support this kind of conditional execution.

Jim

Dell Hershwtized

9:11 am on Nov 21, 2006 (gmt 0)

10+ Year Member



Lets have a example.

say i had a folder name "article" as [abc.com...]

Now in that folder i m keeping this rule.

RewriteRule ^(index¦rss¦redirect¦texvc)\.php$ - [L]
RewriteRule ^(.*)$ index.php?id=$1 [L,QSA]

so if someone access like [abc.com...] it will go as index.php?id=planning_loan

Now there are some other files also like index.php, rss.php etc which i dodnt want to apply this rule. so i had kept rule 1 above for them.

Now what happens there are also some sub-folders under the "article" folder say admin,css,data etc.

now on those folder, there also some php files. so when some access like [abc.com...] it will go as index.php?id=login which I DODNT want.

So is there any way to stop applying this rules to sub folders.
OR can i write this rules in some other way?

Thanks in advance.

jdMorgan

1:46 pm on Nov 21, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can do it all with one rule, and add a RewriteCond to prevent <anything>/<any character><anything> from being rewritten:

RewriteCond $1 !^(index¦rss¦redirect¦texvc)\.php$
RewriteCond $1 !/.
RewriteRule (.*) index.php?id=$1 [L,QSA]

The second RewriteCond prevents the rule from being applied if a slash followed by any single character is found anywhere within the requested URL-path. Therefore, the rule will be suppressed if any file in any subdirectory below the current one is requested. The $1 refers to the requested path captured in the RewriteRule pattern.

Jim