1

My directory structure is like this.

--index.html
--img
   --.htaccess
   --image.png

index.html simply loads image.png. When someone types mysite.com/img, I want to 1) prevent people from listing img directory and 2) Return 404 error instead of 403 when try to access the img folder.

As per this SO answer, I've created an .htaccess file in the img folder with this content.

Options -Indexes
<FilesMatch /img(/?|/.*)>
    Order allow,deny
    Deny from all
</FilesMatch>

RedirectMatch 404 ^/img(/?|/.*)$

However, when I do this index.html itself can't find image.png anymore and it also gets a 404 error. If I remove the RedirectMatch line from .htaccess then it works but now mysite.com/img returns 403 error.

Is it possible for index.html to load the image and mysite.com/img returns a 404 response via .htaccess file? I'm very new to Apache, so not sure if these sounds naive or the requirements are kind of mutually exclusive/

Community
  • 1
  • 1
kaushal
  • 785
  • 12
  • 27

0 Answers0