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

but that didn't work.

2 Answers 2


Try this:

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.