1

I want to redirect users if they access the gif images directly.

http://www.example.com/uploads/file.gif
This should be redirected to home page or some other page.

Or

If the image is directly accessed, I want to show a html form or button to go to html form.

location ~* (\.gif)$ {
  rewrite ^/* /imagedisplay/ last;
}

I tried to use redirect but it didn't help.
Please advice to prevent images to be hot linked.

Anatoly
  • 556
  • 3
  • 16
Mahesh
  • 237
  • 1
  • 3
  • 16

1 Answers1

2

Probably you ask how to prevent hotlinking? Nginx has built in functionality to do that: http://nginx.org/en/docs/http/ngx_http_referer_module.html

See an example below:

valid_referers none blocked server_names
               *.example.com example.* www.example.org/galleries/
               ~\.google\.;

if ($invalid_referer) {
    return 301 http://example.com;
}
Anatoly
  • 556
  • 3
  • 16