Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Google Image Search have the ability to point to the original image without displaying the website that's hosting the image. So I want to redirect those requests to a custom page of my site.

Basically I want to rewrite all this urls (referred from google):

www.website.com/folder1/folder2/year/month/day/ID/string.jpg

to redirect to:

www.website.com/ID/page.html

I've tried this code:

set $button_redirect 0;
if ($http_referer ~ "\.google\.") { set $button_redirect 1; }
if ($http_referer ~ "\.google\.[^/]+/blank\.html") { set $button_redirect 0; } 
if ($http_user_agent ~ "Googlebot|bingbot|Slurp|Baiduspider|Yandex|Sogou") { set $button_redirect 0; }
if ($button_redirect = 1) {

    rewrite ^(.*)/folder1/folder2/([0-9]{4})/([0-9]{2})/([0-9]{2})/([0-9]+)/(.*)\.jpg$ /index.php?/$4/page.html last;

}

but when I restart the server not a single page is loaded, so I think that I made at least a mistake. Can you help me? (I'm running Codeigniter).

I've took most of the code from here: http://pixabay.com/en/blog/posts/hotlinking-protection-and-watermarking-for-google-32/.

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.