Reputation: 102
I have a folder structure like this:
subdir
|_ subsubdir
|_ index.php
|_ other_stuff.php
|_ images
|_ pic.jpg
.htaccess
config.ini
index.php
Content of the .htacces file:
Options +FollowSymLinks -MultiViews -Indexes
Order Deny,Allow
<FilesMatch "(\.ini$)|(\.php$)|(^\.)">
Deny from all
</FilesMatch>
<Files index.php>
Allow from all
</Files>
My goal is to keep users from viewing subdir/subsubdir/index.php (and all other *.php files, no matter where, but this works already) but allow them to see the index.php in the root directory.
Currently, the user is obviously still able to see subdir/subsubdir/index.php, because all files named "index.php" are allowed, but I have no idea how to allow just the one in the root directory and deny all others. I have tried different things but endet up either completely denying or allowing them all.
I feel like this should be a very easy task but I just can't figure it out.
Things I have tried:
<FilesMatch "\.\/index\.php">
Allow from all
</FilesMatch>
---
<FilesMatch "^index\.php$">
Allow from all
</FilesMatch>
---
<Files ./index.php>
Allow from all
</Files>
---
<Files /index.php>
Allow from all
</Files>
Upvotes: 3
Views: 1153
Reputation: 786091
Comment out both FilesMatch
blocks:
And use this code:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index\.php$ [NC]
RewriteRule ^\.|\.(ini|php)$ - [F,NC]
Upvotes: 5