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

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

to redirect to:

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:

share|improve this question

Your Answer


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

Browse other questions tagged or ask your own question.