Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to stop sub directory inheriting parent's htaccess rules

My main public_html directory has the following .htaccess rules:

Options +FollowSymLinks
IndexIgnore */*
<IfModule mod_rewrite.c>
RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php
</IfModule>

The problem is, I then have a subdirectory called source, and I want that directory to just list the files within it (because there is no index file). The problem is the above parent directory's htaccess rules are causing no files in source to be shown in the directory index (it just lists a blank index).

How can I solve this?

THANKS

like image 567
user1280853 Avatar asked Mar 29 '12 12:03

user1280853


2 Answers

Change your .htaccess with this:

Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# if request is not for the /sub-dir/
RewriteCond %{REQUEST_URI} !^/sub-dir/ [NC]
# otherwise forward it to index.php
RewriteRule . index.php
</IfModule>
like image 102
anubhava Avatar answered Oct 22 '22 17:10

anubhava


This may be obvious and you've already tried it - but have you created an .htaccess file in the subfolder of interest? Any settings in this file will override equivalent settings in the root folder.

UPDATE:

For the root .htaccess file, instead of IndexIgnore */* ... try Options -Indexes

Then, in the subfolder's .htaccess file, place this single line: Options +Indexes

Does that achieve the desired effect?

like image 28
Dan Nissenbaum Avatar answered Oct 22 '22 16:10

Dan Nissenbaum