• Trying to block hotlinking for both “mydomain.com” and “www.mydomain.com”. My code does not block hotlinking from “mydomain.com”.

    My current .htaccess code is:

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^https://(www.)?mydomain.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !google. [NC]
    RewriteCond %{HTTP_REFERER} !search?q=cache [NC]
    RewriteCond %{HTTP_REFERER} !msn. [NC]
    RewriteCond %{HTTP_REFERER} !yahoo. [NC]
    RewriteRule .*.(gif|jpg|png|ico)$ – [F,L]
    </ifModule>

    What can I add to block hotlinking images from “mydomain.com” without the “www”?

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Thread Starter atdblog

    (@atdblog)

    May have been confusing … meant to say …

    A blog cannot hotlink to my image at “https://www.mydomain.com/wp-content/uploads/2012/02/elephant_quote.jpg”

    But they can still hotlink to my image at “https://mydomain.com/wp-content/uploads/2012/02/elephant_quote.jpg&#8221;

    I appear to be missing some code in my .htaccess.

    Thread Starter atdblog

    (@atdblog)

    Ok, the code above seems to be working today. I thought I had my cache cleared but I guess I didn’t.

    Thread Starter atdblog

    (@atdblog)

    Others may find this “stop hotlinking” code useful …

    My root .htaccess file now looks like this:

    # 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>
    
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^https://(www.)?mydomain.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !^https://(www.)?seconddomain.com/.*$ [NC]
    RewriteCond %{HTTP_REFERER} !google. [NC]
    RewriteCond %{HTTP_REFERER} !search?q=cache [NC]
    RewriteCond %{HTTP_REFERER} !msn. [NC]
    RewriteCond %{HTTP_REFERER} !yahoo. [NC]
    RewriteCond %{REQUEST_URI} !^/pages/images/
    RewriteRule .*.(gif|jpg|png|ico)$ – [F,L]
    </ifModule>
    
    # END WordPress

    Where “mydomain.com” is my site, “seconddomain.com” is a site I allow to hotlink my pics, followed by allowing search engines to hotlink my pic, and finally a condition to allow anyone to hotlink pics from my non-WP “pages/images” directory.

    Thread Starter atdblog

    (@atdblog)

    And if you replace this line
    RewriteRule .*.(gif|jpg|png|ico)$ – [F,L]

    with this line
    RewriteRule .*.(gif|jpg|jpeg|png|ico)$ https://www.mydomain.com/pages/images/hotlinkingisbad.jpg [R,NC,L]

    Anyone who attempts to hotlink will be served with an image (that you create) saying something like “hotlinking is bad, please save the image for your site”. The image must reside in the directory where you allow hotlinking (pages/images in this case).

    Fyi: You can test your code to prevent hotlinking at a number of test sites, including this real-time editor https://techgyo.com/HTML-Editor.htm (remember to clear your cache, first and often).

    I am looking for solution of this difficult question. I guess i got it. Thanks for sharing.Austin rentall and Rental Apartments

    Thanks for the code.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘How to stop hotlinking with www and without www’ is closed to new replies.