Arjen
Arjen

Reputation: 1161

How to serve only images using htaccesss but not the folder

Currently i have this:

#Expections
RewriteCond %{REQUEST_URI} ^/uploads.*$
RewriteRule ^(.*)$ - [L,NC]

This serves the entire folder uploads. But I want to serve the images inside, not the entire folder. Meaning, if somebody types in: mydomain.com/uploads, I don't want them to see a list of images inside that folder but I want to say, forbidden. Only if they have the exact URL they can see the image.

Upvotes: 0

Views: 31

Answers (1)

Phil Y
Phil Y

Reputation: 206

You need to add an option to Apache to disable the displaying the contents of a folder

<Directory /var/www/.../uploads>
    Options -Indexes

</Directory>

Replace "..." with the location of your website. If there are other options within the Directory command, keep those.

Upvotes: 1

Related Questions