Rewrite the url address using nginx and forward it to the rewritten address

for example:
request http://xxx.com/pro/class-mode
is actually forwarded to address http://xxx.com/pro/class/model
while request http://xxx.com/pro/class is not forwarded
where pro , class , mode are all variable values, regardless of the fact that they contain - (horizontal line)
requires that the browser address bar url cannot be changed

my idea is to use rewrite and proxy_pass to match a route that meets the rules, then rewrite the route, change the middle horizontal line to a slash, and then forward the rewritten route, but it always has the effect of redirection.
Thank you very much for your answers, Crab

Oct.20,2021

rewrite will of course redirect. Just forward it.

location /(.*?)/(.*?)-(.*?)/ {
    proxy_pass http://xxx.com/$1/$2/$3/;
}

give it a try

Menu