Why do not redirect maps work with static files?

Viewed 14

I'm trying to configure redirect_maps with nginx for a serie of PNG images that I moved to a folder. E.g. /images/2022/stackoverflow.png becomes /images/anewfolder.... I need to specify where the new path is so I was thinking about using redirect_maps.

In my configuration file, I have put:

map $request_uri $redirect_uri{
    /images/2022/stackoverflow.png /images/newfolder/stackoverflow.png;
}

server {
 [.. redacted for sensitive data ..]

     location / {

        if ($request_filename !~* .(gif|webp|jpe?g|png|json|ico|js|css|flv|swf|pdf|xml)$ ) {
            rewrite ^([^.]*[^/])$ $1/ permanent;
        }

        if ($redirect_uri){
            return 301 https://google.com$redirect_uri;
        }

        # First attempt to serve request as file, then # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
        }
}

It seems redirect maps work perfectly with uri that do not have "." inside the $request_uri.

0 Answers
Related