'How to prevent redirect if image is embedded on page? [nginx]

My nginx conf is set to reverse proxy port 8081 and to redirect if a user try to direct access any image by browser. However I do not want to redirect if a image is embedded on the page using <img src=""/>

this is my nginx conf

location ~ "^/c/600x1200_90_webp/img-master/img/\d+/\d+/\d+/\d+/\d+/\d+/((?<filenum>\d+)[^/]+\.(jpg|png|webp))$" {
proxy_pass http://xxx.xxx.xxx.xxx:8081;
valid_referers server_names;
if ($invalid_referer = "1") {
return 301 http://example.com/detail?id=$filenum; }
}

How can I fix this cause it's redirecting the embedded images which I don't want?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source