Search code examples
phpimage.htaccesshotlinking

Redirect linked image to content page


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.


Solution

  • 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)