Search code examples
.htaccesshotlinking

Stop hotlinking from another IP


I have a lot of domains and these hosting on only one IP.

I tried to use this below code in htaccess to protect hotlinking, but it doesn't work.

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?103.222.219.45/.*$ [NC]
RewriteRule \.(jpg|jpeg|png|gif|ico|pdf|zip|js|css)$ - [F]

How can I protect hotlinking form another IPs?


Solution

  • The referer header contains the URL of the previous page. It will only contain the IP address if the IP address was used in the URL instead of a host name.

    You need to explicitly specify each of the acceptable host names.