3

I have several sites hosted on a Bluehost server. I would like my sites to be able to use each others' images. In other words, I want to let my sites hotlink images from each other.

There is an option in the Bluehost cPanel to turn hotlink protection off. Turning it off solves the problem. However, I don't want to leave my sites open to hotlinking by other people.

I have found that I'm supposed to add a rule like this to the .htaccess file of the hotlinked site:

RewriteCond %{HTTP_REFERER} !^http://example.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://example.com$      [NC]
RewriteCond %{HTTP_REFERER} !^https://example.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^https://example.com$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^http://www.example.com$      [NC]
RewriteCond %{HTTP_REFERER} !^https://www.example.com/.*$      [NC]
RewriteCond %{HTTP_REFERER} !^https://www.example.com$      [NC]
RewriteRule .*\.(jpg|jpeg|gif|png|bmp)$ - [F,NC]

What this is supposed to do is block all hotlinking except for www.example.com. However, it doesn't work, it blocks everything, including requests from www.example.com. I suspect the value of %(HTTP_REFERER) is empty or malformed. Is there any way to check the value of HTTP_REFERER?

1

This will return a 403 “Forbidden” response whenever any of these file extensions are requested from a site other than your own.

RewriteRule \.(gif|jpe?g?|png|mp3|mp4|wmv|flv|avi)$ - [NC,F,L]

You also need to add the site exception rule underneath the hotlinking rule. The .htacces file works in a cascading fashion just like a CSS file. So those (example.com) rules in your above example need to go below the last rule.

You can also use this underneath the above rule for any domain you wish to whitelist:

RewriteCond %{HTTP_REFERER} !^https://www.example.com/(m/)?view/ [NC]
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.