Redirect linked image to content page

1.7k Views Asked by At

I have an image/video hosting site. In the likes of imgur. A lot of 'link-juice' I get is from people directly linking to the images. I dislike this. I want the ones that land on those pictures to be redirected to the actual page the images resided on.

Now the structure is as follows:

http://www.funzors.com/uploads/images/225.jpg <- image

http://www.funzors.com/media/225-pull-up-your-pants/ <- content page.

Is this wise to do? And if so, how do I do it with htaccess? My guess:

  • Check if referrer isnt funzors.com, and also check if it isnt google (Don't need google disliking my redirection)
  • redirect without status code to the content page.
  • check if people dislike this

THank you in advance.

2

There are 2 best solutions below

2
On BEST ANSWER

Put this in the htaccess that is inside the /uploads/images folder.

RewriteEngine On
RewriteBase /uploads/images
RewriteCond %{HTTP_REFERER} !funzors\.com
RewriteCond %{HTTP_REFERER} !google\.
RewriteCond %{HTTP_REFERER} !^$
RewriteRule ^225\.jpg$ /media/225-pull-up-your-pants/ [R,L]

This will redirect iff: the referer does not contain funzors.com and does not contain google. (note I do not specify the tld, as it is different for different countries) and the referer is not empty (some proxies and software remove the referer; also googlebot doesn't send referers)

2
On

Browser are expecting an image, because the image is hotlinked using something like <img src="http://www.funzors.com/uploads/images/225.jpg" />. So if the browser get html instead of jpeg data, it will just show the broken image icon, or not show the image at all.

You could just redirect to another image that contains an "ad" for your website. You could make it a very big image, so all the other content on the hotlinking site gets pushed of screen :-) You could even create a nice gif or something

As for the referer. The referer for an embedded image is the url of the page it is on, so it's not the same as the referer of the page itself. You should however also allow google/yahoo/etc if you want to allow image search on your site. I don't think google's crawlers send referer headers, so bot-wise you are good.