Can't stop Image Hotlinking. Please check my code. (2 posts)

  1. neha_joshi_rocks
    Posted 1 year ago #

    This is my code in .htaccess
    Hotlink protection is not working for me.
    I want to show a custom image.
    What I am doing wrong? Check my code and please tell me what should I do to correct it.

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?hotmug.org [NC]
    RewriteRule \.(jpg|jpeg|png|gif)$ hotmug.org/no-hotlink.png [NC,R,L]
    # END WordPress
  2. Deleted bump. Please don't. Everyone's a volunteer here, so sometimes we're busy.

    First, put the hotlink protection ABOVE the WP lines. It should always be WP Last :)

    My preferred code is this:

    # ultimate hotlink protection
    <IfModule mod_rewrite.c>
     RewriteEngine on
     RewriteCond %{HTTP_REFERER}     !^$
     RewriteCond %{REQUEST_FILENAME} -f
     RewriteCond %{REQUEST_FILENAME} \.(gif|jpe?g?|png)$           [NC]
     RewriteCond %{HTTP_REFERER}     !^https?://([^.]+\.)?domain\. [NC]
     RewriteRule \.(gif|jpe?g?|png)$                             - [F,NC,L]

    However you're trying to show a PNG, so you will have to put in an exclusion for that. Frankly, I wouldnt bother. Just break the link.

Topic Closed

This topic has been closed to new replies.

About this Topic