0

I can't find the way to redirect the lang set in url with Nginx.

I tried this:

location ~ ^/(en|fr|de)/cloud/signup {
  return 301 $scheme://cloud.$host/$1/home/new;
}

Also this:

location ^/(.*)/cloud/signup {
  return 301 $scheme://cloud.$host/$1/home/new;
}

It doesn't work. Note that setting the lang in location works:

location /en/cloud/signup {
      return 301 $scheme://cloud.$host/en/home/new;
    }

But I don't want to create 1 location block per language of course. Thanks.

alex.bour
  • 111
  • 1
  • 5
  • 1
    FWIW your first example works for me. Your second example is missing a `~`. – Richard Smith Jan 11 '16 at 09:52
  • Thanks Richard. Don't know what happens. It's working now (example 1 and example 2 adding the ~) – alex.bour Jan 11 '16 at 10:21
  • Can I ask you how to make this: `location ~ ^/(en|fr|de|it|es|pt) { return 301 $scheme://apps.$host/$1; }` not the priority ? What I need to add after `/(en|fr|de|it|es|pt)` to match that there is no extra path after `example.com/lang` ? So that all my other redirects with paths will work before the main one. – alex.bour Jan 11 '16 at 11:21
  • 1
    See `location` directive [documentation here](http://nginx.org/en/docs/http/ngx_http_core_module.html#location). In brief: Your regex locations are *ordered*. Your prefix locations are above or below the regex locations in terms of precedence, by the presence or absence of the `^~` modifier. – Richard Smith Jan 11 '16 at 11:40
  • Thanks. As I have just routes with regex (15 locations), I just reordered them. It works. – alex.bour Jan 11 '16 at 12:31

0 Answers0