Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow/deny image hotlinking with .htaccess

So I've got this in my site .htaccess file to prevent hotlinking of images, JS and CSS from all other domains.

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com [NC]
RewriteRule \.(gif|jpe?g|js|css)$ - [F,NC,L]

Question: How would I selectively allow one or two domains to hotlink?

like image 934
markratledge Avatar asked Aug 07 '09 16:08

markratledge


People also ask

How do I stop image hotlinking in WordPress?

From the WordPress dashboard, install the plugin and activate it. Navigate to the WP Security menu -> Firewall -> Prevent Hotlinks. Select Check this if you want to prevent hotlinking to images on your site.

What does stop this image was Hotlinked mean?

What image hotlinking is (and why you should prevent it) Image hotlinking is when someone embeds your images on their website by linking them directly from your website. It's bad enough when people use your media without permission, but image hotlinking adds insult to injury since it can also slow down your site.

What does no hotlinking mean?

Hotlinking is known as the act of stealing someone's bandwidth by linking directly to their website's assets, such as images or videos. For example, let's say the owner of website A is hosting a particular image on their server.


1 Answers

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?mydomain\.com [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?otherdomain\.com [NC]
RewriteRule \.(gif|jpe?g|js|css)$ - [F,NC,L]

Will work, as this says.

"Refererr is not nothing, and referer is not matching mydomain and referer is not matching otherdomain.

If it were the case that you were trying to do the opposite (blacklist a set of domains from hotlinking) you'd do something like

RewriteCond %{HTTP_REFERER} ^http://(www\.)?baddomain1\.com [NC,OR]
RewriteCond %{HTTP_REFERER} ^http://(www\.)?baddomain2\.com [NC]
RewriteRule \.(gif|jpe?g|js|css)$ - [F,NC,L]
like image 65
Mez Avatar answered Sep 28 '22 05:09

Mez