Nginx的 – redirect到不同的url,如果图像是直接访问

我想redirect用户,如果他们直接访问GIF图像。

http://www.example.com/uploads/file.gif
这应该被redirect到主页或其他页面。

要么

如果图像是直接访问,我想要显示一个HTML表单或button去HTML表单。

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

我试图使用redirect,但没有帮助。
请build议,以防止图像热链接。

可能你问如何防止盗链? Nginx已经build立了这样的function: http : //nginx.org/en/docs/http/ngx_http_referer_module.html

看下面的例子:

 valid_referers none blocked server_names *.example.com example.* www.example.org/galleries/ ~\.google\.; if ($invalid_referer) { return 301 http://example.com; }