Blocking Hotlinking to images and files in WordPress with a self-hosted block image.

It’s fairly common to find how-to’s that show you how to use .htaccess to block hotlinked images, but it seems a lot of them show you to redirect to an outside file. Not sure why that’s a good idea, or not mentioned, but meh.

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{REQUEST_FILENAME} !/hotlinking.jpg
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)? [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)? [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)? [NC]
RewriteRule \.(jpg|jpeg|png|gif) [NC,R,L]

Now, the important rules are in the second and last lines. The last line redirects any hotlinked images (which don’t come from your sites’ domains. The second line un-blocks the redirect protection for only that image.

The five or six different howtos I tried to use this afternoon didn’t include this salient point 🙁

#Apache #coding #Hot LInked Images #Hotlinking #htaccess #Wordpress