Score:0

Nginx redirect path to different path

cn flag

I'm trying to redirect urls with Ninx but i'm struggling to get it right:

example.com/{dynamic1}/foo/bar/{dynamic2} to example.com/{dynamic1}/bar/{dynamic2}

basically i'm trying to remove the /foo/ portion of the url.

i've tried the following:

location ~* ^/(.*)/foo/bar/(.*)$ {
  return 302 ^/$1/bar/$2?$args;
} 

and also:

location ~ ^/([^/]*)/foo/bar/(.*)$ {
  return 302 ^/$1/bar/$2?$args;
}

but this throws the error 414 Request-URI Too Large and the url ends up being (shortened for clarity):

dynamic1/cams/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/%5E/dynamic1/bar/dynamic2?

What am I doing wrong?

Note that once i get this right i will replace 302 with 301.

Score:0
cz flag

You have placed a caret at the beginning of the destination URL path that you appear to have intended to redirect to. This does not belong there, and it is why %5E shows up repeatedly.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.