I want to get a dynamic 404 response depending on the requested url:
foo.jpg doesn't exist
http://example.com/img/style/thumbnail/foo.jpg
should show
http://example.com/img/notfound/thumbnail.jpg
with a 404 header status
I got the rewriting part right, but i can't seem to get it return with a 404 status code.
I tried this with the following code, but without success:
location ~ /img {
if (!-f $request_filename){
rewrite "^(.*img\/)style\/([a-zA-Z\_\-[0-9]*)\/?(.+)" $1notfound/$2.jpg;
#so far so good. Now i want to return the rewrite result as a 404 response
error_page 404 = $request_filename;
return 404;
}
}
This gives me the default nginx 404 error page instead of the rewritten url with 404 status code. How can i tell nginx to use the rewrite result as 404 error page?