Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Redirect hotlinked image to Coral Cache



10:12 pm on Mar 27, 2007 (gmt 0)

10+ Year Member

Hi everyone,

I'm seeing a huge increase in hotlinking to images on my site - particularly with referrals from the far east. A whole page of mine will be posted to a forum with translated text and hotlinks to my images.

I don't particularly mind this, but I'm beginning to be concerned about BW.

It occurred to me that I could use htaccess to rewrite the URL to redirect image request from off-site to the a Coral Cached version.

I came up with this, and I'm looking for a reality check.

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_USER_AGENT} !^CoralWebPrx
RewriteCond %{QUERY_STRING} !(^&)coral-no-serve$
RewriteRule images/(.*)$ http://example.com:8080/images/$1 [R,L]

I mixed anti-hotlinking examples and the example from the Coral CDN page and it seems to work.

Does it look robust to you Mod_ReWrite experts?
Am I correct that it will not effect search engine spiders?
Any other unforeseen issues?



[edited by: jdMorgan at 4:03 am (utc) on Mar. 28, 2007]
[edit reason] Examplified, disabled smileys in code. [/edit]


2:31 pm on Mar 28, 2007 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

It looks OK; Only thorough testing can reveal subtle problems.

Search engines typically do not provide a referer -- None of the major ones do. So this should not affect the major search engines.

If it were my code, I'd make a few small changes for efficiency, clarity, and robustness:

RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com(/:[0-9]+)? [NC]
RewriteCond %{HTTP_USER_AGENT} !^CoralWebPrx
RewriteCond %{QUERY_STRING} !(^&)coral-no-serve&?
RewriteRule images/(.*)$ http://example.com:8080/images/$1 [R=302,L]

The regex pattern "." is equivalent to "!^$", but shorter and faster to process (If a string contains any character, then it is also NOT blank).

There is no use checking the entire referrer pattern if the Referrer is blank, so reverse the RewriteCond order.

A port number may be appended to the hostname in the referrer, and should be accepted.

The slash after the domain name may or may not be present, so omit that requirement.

The query string name/value pair order should be flexible at both ends.

Make it clear to the reader that this is a 302 (Temporary) redirect.

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



4:17 pm on Mar 28, 2007 (gmt 0)

10+ Year Member

Thank you so much!



Featured Threads

Hot Threads This Week

Hot Threads This Month