How to prevent hotlinking with htaccess in WordPress and why most common use about it doesn’t work?

when I paste the URL of image

I assume you mean when you paste the URL directly into the browser’s address bar, as I can’t think you’d be pasting it anywhere else. (?)

If that is the case then the behaviour you are seeing is correct – the browser should show the image. This isn’t really “hotlinking”, this is a direct request. You can’t realistically block direct requests (when the HTTP Referer is empty) as you could end up blocking these images for real users of your site that don’t send the HTTP Referer header as part of the request.

The following condition is what allows this request to happen:

RewriteCond %{HTTP_REFERER} !^$

ie. When the HTTP_REFERER is not empty.


ASIDE: You’ve tagged your question “multisite”, however, you appear to have both sets of code in your .htaccess file: standard single-site and multi-site? The single-site code is first, so this is what’s “winning”.

Leave a Comment

tech