1

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 ?

1
  • Are you saying that one URL could point to any number of target file names? If it's a finite set, you could try each filename in succession using try_files, but it is neither efficient nor extensible. Commented Aug 25, 2022 at 11:44

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.