Deny all files, but index/default page with htaccess

.htaccess, apache

Solution

Your problem is, as you may have figured it out, that you're denying all the stuff, then allow the URI 'index.php', but not the URI '/' -- even though the '/' gets redirected to the index.php behind the scenes, it's still a different URI, and thus it should be allowed too.

The easiest way to do it is using the FilesMatch directive, like this:

order allow,deny
<FilesMatch "^(index\.php)?$">
    allow from all
</FilesMatch>

The regex `^(index\.php)?$` means "index.php or nothing".

Problem

I would like to deny all files in a directory, but index.php (as being the default page). This solutions works almost: ``` Deny from all <Files index.php> Order Allow,Deny Allow from all </Files> ``` The only problem: 'upload/index.php' is now accessable, but '/upload/' isn't. How can I allow the default page with htaccess?

Original source