Need to filter specific domain in hotlinking rule in htaccess

Posted on 2008-11-05
Last Modified: 2012-05-05
I have the following code in my .htacess file to prevent hotlinking. However, I now need to allow linking from I suspect it is a second rule?

RewriteEngine    on
RewriteCond    %{HTTP_REFERER} !^$
RewriteCond    %{HTTP_REFERER} !^http://([-a-z0-9]+\.)?MYDOMAIN\.com [NC]
RewriteRule    \.(gif|jpe?g|png)$ - [F,NC,L]

Many thanks for input,
Question by:pcoghlan
    LVL 27

    Accepted Solution

    Just a modification to your condition:

    ( | stands for "or")
    RewriteEngine    on
    RewriteCond    %{HTTP_REFERER} !=""
    RewriteCond    %{HTTP_REFERER} !^http://([-a-z0-9]+\.)?(MYDOMAIN|OTHERDOMAIN)\.com [NC]
    RewriteRule    \.(gif|jpe?g|png)$ - [F,NC,L]

    Open in new window


    Author Comment

    blimey, that was easy!

    Thanks a million


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
    If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now