Forum Moderators: phranque

Message Too Old, No Replies

Forbidden directory. what about subdirectories?

         

asantos

4:25 pm on Oct 25, 2006 (gmt 0)

10+ Year Member



hi
i implemented this rule so no one can list my inc/ directory files:

RewriteRule ^inc/?$ / [F,NC,L]

It works great! But, what happens if i have another directory inside inc/, which is called 'important'

Is there a way for me to implement a rule that redirects the user if he tries to access inc/ or any of its subdirectories?

DrDoc

4:33 pm on Oct 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



RewriteRule ^inc/important/?$ /inc/important/ [NC,L]
RewriteRule ^inc/?$ / [F,NC,L]

asantos

4:54 pm on Oct 25, 2006 (gmt 0)

10+ Year Member



Thanks for the reply,
is there a way to do it dinamically so i dont have to be setting a redirect for each subdirectory?

DrDoc

5:41 pm on Oct 25, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can always do a generic redirect for subdirectories.

RewriteRule ^inc/(.+)/?$ /inc/$1/ [NC,L]

Note that this doesn't really redirect anywhere (not sure if you have a specific file you want loaded if someone tries to list the directory). If no redirection is needed, you should just use a RewriteCond.

RewriteCond %{REQUEST_URI}!^/inc/.+/ [NC]
RewriteRule ^inc/?$ / [F,NC,L]

asantos

8:39 pm on Oct 25, 2006 (gmt 0)

10+ Year Member



thanks, ill test it at home in a few hours.

jdMorgan

4:09 am on Oct 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Note that removing the end-anchor from the pattern is probably sufficient to achieve the desired behaviour.

RewriteRule ^inc/? - [NC,F]

Also, note the use of "-" as the substitution -- It's a special token, meaning "just leave the URL-path alone, and do the flag stuff". Also, the [L] flag used with [F], [G], or [P] is redundant.

Jim