0

So I've found many posts here on how to do a similar action, however, I'm still confused. So here is my question. I want to have access to www.mywebsite/folder/index.html but if I were to remove the index.html and just type in www.mywebsite/folder/ I don't want to have access to that. How can I go about doing this? I read that I can use an .htaccess file with deny from all but that restricts me from the whole folder and I can't access the index.html.

Please let me know if there is a solution or another post that I missed that outlines the exact situation.

Thank you!

  • unusual request, but i was thinking `DirectoryIndex zzzzzzzzzzzz` make sure there is no zzzzzzzzzzzz file –  Jan 31 '18 at 20:24
  • where do they go if they put nothing in? 404 error page? to me this would make it seem like your site is broken, I think its a bad idea from usability view. – ArtisticPhoenix Jan 31 '18 at 20:25
  • 1
    https://stackoverflow.com/questions/2530372/how-do-i-disable-directory-browsing – Aaron Muslim Jan 31 '18 at 20:30
  • @AaronMuslim awesome, thank you. I got it to work. I really appreciate it! – Mehar Banga Jan 31 '18 at 20:31
  • Possible duplicate of [How do I disable directory browsing?](https://stackoverflow.com/questions/2530372/how-do-i-disable-directory-browsing) –  Jan 31 '18 at 20:37

1 Answers1

1

Which Apache version are you using? In 2.4, you can use DirectoryIndex disabled to stop it from automatically serving up the index.html, and combine that with Options -Indexes.

In lower versions disabled does not exist yet, so using mod_rewrite with a simple RewriteRule that forbids access when the exact folder path (with or without trailing slash) was requested should do it,

RewriteRule ^folder/?$ - [F,L]

To control what error message the user gets to see in each case, specify the ErrorDocument for the 403 Forbidden status code.

CBroe
  • 91,630
  • 14
  • 92
  • 150