I need a quite special rewrite rule but I can’t find the way to do it.
I need to map a uri to a regex to a replacement string built with a regex.
For example I have a /pdv/plan-AGE44-ABC.pdf
uri that could be mapped to the following ones :
/files/AGE44/plan-ABC.pdf
/files/AGE44/plan-ABC(version-1).pdf
/files/AGE44/plan-ABC(version-2).pdf
/files/AGE44/plan-ABC(version-3).pdf
So the (version-1)
part in the replacement string is optional so I thought about using a regex here.
An example of my rule :
location /pdv/ {
rewrite ^/pdv/plan-(.*)-(.*).pdf$ "/files/$1/plan-$2.pdf" last;
return 404;
}
This supports the first case (/files/AGE44/plan-ABC.pdf
) but I can't find the way to support the other ones.
Any idea how I could do this ?