Reputation: 395
I want to make so no one can access particular directory or files directly from browser. But I want to make so above prevented directory and files are accessible through website.
Using below code, I can prevent direct access of 'data' folder from browser. But when I checked from website, all content that is coming from 'data' folder are not displaying (means not accessible).
RewriteRule ^(data/) - [F,L,NC]
Using below code, I can prevent direct access of below mentioned extensions files from browser. But when I checked from website, all content with these extensions are not displaying (means not accessible).
RewriteRule \.(gif|jpg|wmv)$ - [F]
What changes should I make in .htaccess to make it possible?
Upvotes: 0
Views: 144
Reputation: 4302
Try this :
RewriteCond %{HTTP_REFERER} !^https://(www\.)?yoursite\.com/ [NC]
RewriteRule \.(jpe?g|gif|bmp|png)$ - [F]
The problem right now , when someone exploring the page that has one of these files and open the source code , he will be able to browse that file directly from cache unless reloading the page , so if you want to prevent that as well , you could disable cache for specific mentioned extensions but you must know what that means prior to disable caching them .
Upvotes: 0