Mobile app version of vmapp.org
Login or Join
Hamm4606531

: Prevent hotlinking of off-site content? I have a www.example.com site where I serve all static content (e.g. http.//www.example.com/image.jpg) off a CDN with URLs like http://static.example.com/image.jpg

@Hamm4606531

Posted in: #403Forbidden #Apache2 #Cdn #Hotlinking #Htaccess

I have a example.com site where I serve all static content (e.g. http.//www.example.com/image.jpg) off a CDN with URLs like static.example.com/image.jpg
An Apache 2 .htaccess rule prohibits non-empty, non-example.com referrals:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www.)?example.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://example.cloudfront.net [NC]
RewriteRule .(jpeg|jpg|gif|bmp|png|mp3)$ - [NC,F,L]
</IfModule>


I still receive huge amounts of traffic from a very popular website that uses some sort of "news roundup" feature and hotlinks to example.com/image.jpg (instead of static.example.com): this resource exists (for origin pull reasons), but the URL is not published anywhere.

In fact, serving so many 403s is bringing my server down.

How can this kind of hotlink traffic be blocked, or at least, how can it be redirected to the CDN before it reaches and cripples apache2?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Hamm4606531

2 Comments

Sorted by latest first Latest Oldest Best

 

@Heady270

Unless you have your images on a sub-domain, there is no way to separate the traffic before it hits your web server.

One performance tip that might help you is to use both nginx and Apache on the same server. Have apache run on a non-standard port. Have nginx run on port 80 and have it reverse proxy requests to apache. The rewrite rule for the images can be put on the nginx server. You might choose this setup because nginx is faster and lighter than apache and can handle many more of these simple types of requests. Here is a guide for implementing this: tumblr.intranation.com/post/766288369/using-nginx-reverse-proxy

10% popularity Vote Up Vote Down


 

@Turnbaugh106

There is no way to forward the www > cdn without reaching the request on the main server since well they are linking to you.

My advice is not to 301 redirect but rather than just flat out 404, hopefully by doing so they will stop hot linking you.

While this has some traffic on your server it shouldn't be too much and you should consider upgrading your hosting if its a problem.

My Drill Down Advice


Consider upgrading your hosting (IMG Hot-linking actually helps your SEO) A load balancer could serve you well here by doing the 403s, 404s or 301s.
Consider using a 404 if you do not want them hot-linking.


Another option is that you can use robots.txt on your CDN but again, hotlinking these days shouldn't be looked down on since well as I said its impossible to use rel=nofollow on images and it does help your SEO a little bit. I personally would appericate the traffic / links and upgrade my server. But other than that... serve them with a good old 404 if they are linking to something that doesn't exist - they will soon stop.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme