Forum Moderators: phranque

Message Too Old, No Replies

how to allow specific hotlinking?

         

omoutop

9:59 am on Mar 16, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi all...

I make a portal (www.mysite.com) about greek islands and in my htaccess file i have the following code to prevent hotlinking

RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mysite.com/.*$ [NC]
RewriteRule \.(gif¦jpg¦js¦png)$ - [F]

Now the owner of the portal wants to make one site per greek island (www.islnad-name.com) and we want to get banners/images from the first site (www.mysite.com).
In total there will be 45 sites (one basic and 44 specific ones). Total images in basic site are more than 9000 (about 850MB of jpg)

Is there a way to allow hotlinking for my sites and block all others so as to avoid uploading more copies of the images again and again and again?

RedAndy

10:38 pm on Mar 16, 2006 (gmt 0)

10+ Year Member



Hi,

you can add another line for each of the 'islands' that you want to accept hotlinking from eg


RewriteCond %{HTTP_REFERER}!^$
RewriteCond %{HTTP_REFERER}!^http://(www\.)?mysite.com [NC]
RewriteCond %{HTTP_REFERER}!^http://(www\.)?my-other-site.com [NC]
RewriteRule \.(gif¦jpg¦js¦png)$ - [F]

I guess there are quite a few greek islands so this may get quite long over time as you add them?

You could help your server out with a couple of processing effort savers:

- you don't need the trailing .*$ on each of those - it uses processing effort as it checks for a match to .*, which matches everything anyway.

- if you are enforcing www or non-www then you can also lose the pattern match at the start and save your server a little more effort. eg just have [mysite.com...] or [mysite.com...]

hth

Andy

omoutop

7:07 am on Mar 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Thanks for the tip Andy. Yeah there are many Greek Islands and yeah I enforce the www.site.com pattern.

I think the total sites will be 45 eventully, so the server process saving time is a must.

Thanks again

jdMorgan

7:39 pm on Mar 17, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



A low-impact alternative would be to simply use subdomains of the main site for each island. This would eliminate the need to have a rule for each of them.

Jim