location ~ \.png$ { if ($http_cookie !~* "wordpress_logged_in") { return 403; # 403 Forbidden return 301 $scheme://$http_host/sample-page; # Custom Page return 301 $scheme://$http_host/wp-login.php?redirect_to=$request_uri; # wordpress login page } }