4

Could someone help me with apache .htaccess file to deny access to all files and sub directories except for index.html on the documentroot for an apache server?

I tried:

<Location />
    Order deny,allow
    <Files index.html>
        Order allow,deny
    </Files>
</Location>

but that didn't work.

2 Answers 2

11

Try this:

Order allow,deny
Deny from all
<FilesMatch index\.html>
        Allow from all
</FilesMatch>
1
  • Fantastic! Thanks for your help, works like a charm
    – 93196.93
    Jul 13, 2012 at 23:54
0

On Apache 2.4.18, inside an .htaccess file, I found that neither <Files index.html> nor <FilesMatch index\.html> nor <Files ""> etc. reacted to directory-index request URLs ending in a slash; they applied only if the request URL actually ended in index.html. I eventually managed to grant access without authentication to all URLs ending in a /, but require authentication for all other files, with

Require expr "%{REQUEST_URI} -strmatch '*/'"
Require valid-user

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .