Forum Moderators: phranque

Message Too Old, No Replies

Providers that cache pages prior to handing them to the user

Images called from specific providers

         

Terabytes

9:56 pm on Feb 7, 2007 (gmt 0)

10+ Year Member



Since I utilize htaccess to prevent hotlinking of my images, I've noticed that some users can't view images on the web pages...(family members first told me about this issue)

I'm assuming that due to a provider caching the page, prior to handing it to the user, the request for the images on the page does not actually come from my domain it comes from the provider and therefore the user sees no images...because actually they are hotlinking in a certain respect...

It only happens with a couple of providers, and I'm wondering how much business I'm losing because of it..

(am I clear about this issue?)

is there any workaround other than changing my htaccess to allow hotlinking (Not my first choice at all)

if I haven't explained the issue enough, I'll be happy to try again...

Thanks!
Tera

jdMorgan

12:19 am on Feb 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd guess that your anti-hotlinking code blocks blank referrers, and this is causing a problem when an intervening caching proxy (such as is used by many corporations or some ISPs like AOL) requests the image. Without seeing your code, it's impossible to tell, though.

Jim

Terabytes

2:22 pm on Feb 8, 2007 (gmt 0)

10+ Year Member



ok...here's what I'm currently using

(some background...)

I have 1 subdomain I use for customers
and 2 domains pointing to the site

thanks in advance!
=======================

order allow,deny
allow from all

RewriteEngine on
RewriteCond %{HTTP_REFERER}!^http://subdomain.domain1.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://subdomain.domain1.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://domain1.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://domain1.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://domain2.net/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://domain2.net$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.domain1.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.domain1.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.domain2.net/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.domain2.net$ [NC]
RewriteRule .*\.(jpg¦jpeg¦gif¦png¦bmp)$ - [F,NC]

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain1\.com
RewriteRule (.*) [domain1.com...] [R=301,L]

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain2\.net
RewriteRule (.*) [domain1.com...] [R=301,L]

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.domain2\.net
RewriteRule (.*) [domain1.com...] [R=301,L]

jdMorgan

3:20 pm on Feb 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That looks like auto-generated code -- like something that cPanel would create. The whole mess can be replaced with:

Order Allow,Deny
Allow from all
#
RewriteEngine on
RewriteBase /
#
# Block image access (hotlinking) if off-site referrer is present in the request
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://subdomain\.domain1.com [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain1\.com [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain2\.net [NC]
RewriteRule \.(jpe?g¦gif¦png¦bmp)$ - [F,NC]
#
# Redirect non-www domain1.com to www.domain1.com
RewriteCond %{HTTP_HOST} ^domain1\.com
RewriteRule (.*) http://www.domain1.com/$1 [R=301,L]
#
# Redirect www or non-www domain2.net to www.domain1.com
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.net
RewriteRule (.*) http://www.domain1.com/$1 [R=301,L]

Here, we add the first RewriteCond to allow blank referrers, and make the "www." optional and remove the end-anchoring in several of the rules to eliminate all the redundant rules.

The new RewriteCond requires that the HTTP_REFERER request header be non-blank before the other RewriteConds are evaluated and the RewriteRule can be applied.

Allowing blank referrers will allow some hotlinking to occur, but the choice is between that and blocking legitimate users. The presence of the HTTP_REFERER in even legitimate requests simply cannot be relied upon.

Replace the broken pipe "¦" characters above with solid pipe characters before use; Posting on this forum modifies the pipe characters.

If you intend to use cPanel to add and remove access restrictions in the future, I cannot recommend hand-editing the .htaccess file to use this code. If you do this, and then later use cPanel to make further modifications, the result may be a big mess, and it will likely not work. So the choices are either to commit to a hand-edited .htaccess file (and all the research/learning that entails) or to try to use cPanel to include the "Allow blank referrers" option if it is supported. Because of the awful code that cPanel produces (because it using a basic "template" to generate the code), I have long ago given up on cPanel for .htaccess maintenance. But you'll have to make this choice for yourself, because what's important to my sites (performance over convenience) may be less important to yours.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

Terabytes

8:16 pm on Feb 8, 2007 (gmt 0)

10+ Year Member



Thanks for the great info!

I'll adopt this tonight, and see how it goes....

thanks again!
Tera