Prevent Hotlinking?

Hi,

I’d like to prevent image hotlinking on my website.

I’m using the following code:


RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\\.)?domain.co.uk(/)?.*$     [NC]
RewriteRule .*\\.(gif|jpg|jpeg|bmp)$ - [F,NC]

replacing ‘domain’ with the correct value.

Is this the correct way of hotlinking as it doesn’t seem to prevent it on my site :frowning:

Thanks for your help

Regards,

DK

Super apologies for the delay.

So I’m right in thinking:


RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !(www\\.)?domain.co.uk(/)?
RewriteRule .*\\.(gif|jpg|jpeg|bmp)$ - [F,NC]

would do the job fine?

Thanks again

Michael,

Close enough for government work (because the {HTTP_REFERER} is notoriously unreliable). Your code says:

If the referrer is not empty AND

If the referrer is not (your domain with optional www) AND

If the file extension is (in the list), FAIL the request.

Question: WHY the NC flag in the RewriteRule? Have you mixed the capitalization of your file extensions? If not, get rid of the No Case flag as it’s not necessary.

Regards,

DK