Reputation: 10030
My .htaccess file:
DirectoryIndex index.php
order allow,deny
<FilesMatch "^(index|testfile)\.php$">
Allow From All
</FilesMatch>
Denies access to the sites root, which would typically open index.php. The only way to load the site is to go to mysite.com/index.php
instead of mysite.com
If I remove the order
it works as expected, but now any files in that directory are accessible.
How do I configure the htaccess to deny all files except index.php
but also allow for navigation to mysite.com
instead of mysite.com/index.php
?
Upvotes: 0
Views: 664
Reputation: 784988
You can do it like this:
DirectoryIndex index.php
order Deny,Allow
# deny everything except landing page
<FilesMatch ".">
Deny From All
</FilesMatch>
# allow index.php and testfile.php
<FilesMatch "^(index|testfile)\.php$">
Allow From All
</FilesMatch>
Alternate Solution using mod_rewrite
:
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !\.(?:css|js|png|jpe?g|gif|ico|tiff)$ [NC]
RewriteRule ^(?!(index|testfile)\.php). - [F,NC]
Upvotes: 1