Stop hotlinking from outside domains by using .htaccess?

How to stop hotlinking from outsides domains.

You can stop the hotlinking from outsider domain by using following rule in .htaccess

RewriteEngine On
RewriteCond %{HTTP_REFERER} ^http://(.+.)?domain.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+.)?domain1.com/ [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(.+.)?domain2.com/ [NC]
RewriteRule .*.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpe [L]

You can also display a 403 Forbidden Error page instead of an image (nohotlink.jpe)

Replace last line on above code with the following code

RewriteRule .*.(jpe?g|gif|bmp|png)$ – [F]

About Anant 384 Articles
Senior technical writer