0

I am very new to nginx but i have been tasked with doing some rewrite rules to cover a new URI structure as part of a website migration. I have browsed this site and i see that there is a solution that I'm not sure will work for us.

Basically i take a URL like abc.com/l/hello+there and replace it with abc.com/address/hello-there

So the replacement of the "/l/" to "/address" is easy, but the replacement of the "+" to "-" seems very tricky as I cant seem to manipulate the variable $2, where it sits.

Has anyone any suggestions ? It was suggested that i just redirect it to a javascript back end as it would be much easier to handle there. If there was a solution where the "+" to "-" replacement could happen in the server block, and then passed to the location block for the processing of the "/l/" to "/address".

Any suggestions would be greatly accepted.

  • 1
    What have tried so far? – Richard Smith Oct 09 '16 at 21:34
  • If you're happy to use openresty then you could do this fairly easily in the access_by_lua block. – Chris Tanner Oct 10 '16 at 08:33
  • HI .. Thanks for the response. I haven't heard of Lua actually, but after a quick google, it reads as if its more powerful. How would something like that look ? – kemistry Oct 11 '16 at 00:16
  • Actually, an important thing to note, the URI will not always be the same structure, it may be something like /hello+there+everyone, for example. Basically the URI doesn't have a predefined structure, only that it will contain a variable amount of "+". – kemistry Oct 11 '16 at 01:42

0 Answers0