Sudhir Bastakoti
Sudhir Bastakoti

Reputation: 100205

How do i restrict direct access (from browser) to a folder but allow access to image files inside it..?

I'm having problem with htaccess. what I want to do is when a user accessed my folder named images from a browser I want to restrict it, but when accessing image files inside it, I want to display the image in the browser. Tried the following code but no success.

<FilesMatch "\.(gif|jpe?g|png|pdf)$">
Allow from all
</FilesMatch>

<Directory>
Order deny,allow
Deny from all
</Directory>

So, can you please suggest something?

Upvotes: 2

Views: 7331

Answers (2)

KodeFor.Me
KodeFor.Me

Reputation: 13521

You can simply add an empty index.html. This will stop the direct access to that folder.

Another solution is that:

Options -Indexes

Enter the above code into htaccess. That will produce a 403 HTTP Status code on folder access, but will allow you do share the content !

Upvotes: 10

Quentin
Quentin

Reputation: 944431

Turn indexes off in the options.

Options -Indexes

Upvotes: 4

Related Questions