I am working on wordpress multisite. I have Total 4 Sites.Only Main site is working good. In other 3 sites I am facing issue for images - "This image was hotlinked"

- 739
- 11
- 28
-
Assuming for the sake of `until proven guilty` that you are authorized to hotlink the images, what kind of protection is used? I think you have to somewhat exclude your domains or include them in some sort of whitelist – salvatore Feb 01 '19 at 15:59
-
@salvatore How do I include them in whitelist ?? – Parthavi Patel Feb 01 '19 at 16:52
-
I need to know the pretection that you are using to tell you for sure, if it's `.htaccess` based, you have to add a few lines to allow your websites. – salvatore Feb 01 '19 at 16:56
-
@salvatore I have already tried and add all possible code in .htaccess file, but nothing works. Any other solution than .htaccess ?? – Parthavi Patel Feb 01 '19 at 17:01
-
Can you add the contents of .htaccess file to your question? replace sensitive information with # if needed – salvatore Feb 01 '19 at 17:02
-
When I **Inspect** original image is there, When I open Image Link in new tab **hotlinked** image is display and then when I refresh Image Link page original image is display. But still in whole site **hotlinked** images are displayed. – Parthavi Patel Feb 04 '19 at 05:33
-
Also when I re-upload image from back-end , it is still showing **hotlinked** in back-end and in front-end. – Parthavi Patel Feb 04 '19 at 06:01
-
Maybe the `.htaccess` is messed up, but i think it's just that whoever wrote it didn't take into account the multisite installation – salvatore Feb 04 '19 at 06:05
-
If you set to rewrite all images not coming from domain1 to the placeholder, but then you open the site using the domain2, it will obviously rewrite all the images, because domain2 is not domain1, even if you are in the admin panel – salvatore Feb 04 '19 at 06:10
1 Answers
It's difficult to give an answer based on so many assumptions, but i'll try.
Assuming that:
You use apache as the webserver
You have 3 different domains that point to the same directory on the same server
You don't have a CDN that may interfere
You don't have installed WP plugins to protect against hotlinking
You use the
.htaccess
file to protect against hotlinkingYou've edited you
.htaccess
adding something like this:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?bing.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yahoo.com [NC]
RewriteRule \.(jpg|jpeg|png|gif|svg)$ http://yourdomain.com/hotlink-placeholder.jpg [NC,R,L]
THEN
You have to add the other domains thet need to access to the images, consider the RewriteCond
list as an exclusion list, that says "Apply the rewrite rule only when the referer is not in this list", so you have to add the other domains to the list.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain.com [NC]
#this
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain2.com [NC]
#and this
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain3.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?google.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?bing.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yahoo.com [NC]
RewriteRule \.(jpg|jpeg|png|gif|svg)$ http://yourdomain.com/hotlink-placeholder.jpg [NC,R,L]
If you can't make the .htaccess
to work properly, consider switching to a plugin, they will manage the file for you
If you need some tool to check you .htaccess
changes before submitting them, take a look at this

- 511
- 4
- 11
-
Yes I write above code in .htaccess , but i wite it only for one domain name. Well I am bit worried to write it for all domain because one site is working good with all images from all that four sites. – Parthavi Patel Feb 04 '19 at 06:12
-
Make a backup of your actual `.htaccess` file that works, and restore it if somethings doesn't work (_this is actually a good practice_). I've edited the answer to give you a tool you can use to check the behaviour of the `.htaccess` file, just remember to try the differente referrers – salvatore Feb 04 '19 at 06:29