Question

I have a doubt in .htaccess

Here is my code :

index.php

Welcome Page
<img src='image/one.png'>

The Image should be visible in the website but it should not be access if entered the url as xxx.com/image/one.png

I am using the following .htaccess

Options -Indexes
ErrorDocument   403 error.php

I read the following question but it didn't cleared me

How can i update my .htaccess file to make it possible ?

Allow file access from code, but block from browser?

Était-ce utile?

La solution

You can do referrer based check to prevent direct access to images. Place this rule in your root .htaccess:

RewriteEngine On

RewriteCond %{HTTP_REFERER} !localhost [NC] 
RewriteRule \.(jpe?g|gif|bmp|png)$ - [F,NC]

But remember that HTTP_REFERER can be manipulated by clients.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top