Forum Moderators: phranque

Message Too Old, No Replies

stop hot linking (domain and subdomains)

.htaccess rewrite....

         

Johnathon222

10:48 pm on Jun 1, 2004 (gmt 0)

10+ Year Member



What syntax do I need to prevent hotlinking images from *both* my main domain and its subdomains?

say my domain is mysite.com

my first subdomain is chat.mysite.com

and my second subdomain is store.mysite.com

Currently I have:

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://mysite.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://mysite.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.mysite.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.mysite.com$ [NC]
RewriteRule .*\.(jpg¨jpeg¨gif¨png)$ - [F,NC]

This was actually done in Cpanel and works great for the main site
but this will block images when people arrive from store.mysite.com/

should it be something like this:

RewriteCond %{HTTP_REFERER}!^http://(www\.)?(store\.)?mysite.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?(chat\.)?mysite.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mysite.com/.*$ [NC]

thanks for any help

Johnny

jdMorgan

11:10 pm on Jun 1, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Covering (allowing) the following referrer domains (upper and lowercase or mixed):

  • <blank>
  • mysite.com
  • www.mysite.com
  • chat.mysite.com
  • store.mysite.com
  • www.chat.mysite.com
  • www.store.mysite.com

    to access the file types (upper and lowercase or mixed):

  • jpeg
  • jpg
  • gif
  • png

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} .
    RewriteCond %{HTTP_REFERER} !^http://(www\.)?(store\.¦chat\.)?mysite.com [NC]
    RewriteRule \.(jpe?g¨¦gif¦¨png)$ - [F,NC]

    (with a lot of uneccessary characters and directives removed.)

    Replace the broken vertical pipe "¦" characters with solid pipes from your keyboard before use.

    Jim

  • gergoe

    11:17 pm on Jun 1, 2004 (gmt 0)

    10+ Year Member



    Try

    RewriteEngine on
    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com(/.*)?$ [NC]
    RewriteRule \.(jpe?g¦gif¦png)$ - [F,NC]

    ...which will accept any referer from your domain name, and from any of the subdomains. I've consolidated the individual RewriteConds, but it has the same functionality as the original one.

    Johnathon222

    11:36 pm on Jun 1, 2004 (gmt 0)

    10+ Year Member



    Thanks for your time guys, looks great, and yeah I kinda wondered if what I had was way too bloated before

    many thanks will try that out now

    Johnny

    Johnathon222

    12:15 am on Jun 2, 2004 (gmt 0)

    10+ Year Member



    Worked great many thanks for your help guys!