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

This should be redirected to home page or some other page.


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.


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/

if ($invalid_referer) {
    return 301 http://example.com;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.