Nginx temporary redirect for new url with replacing

Viewed 114

We are going to change our URL from ourdomain.com/en (ourdomain.com redirects to ourdomain.com/en today) to ourdomain.com/

So many of our urls are on the format ourdomain.com/en/company. We want this to become ourdomain.com/company if it contains en after the first slash. My skills with regex are limited so I have not quite figured it out yet (in our location block /). Will let you know if I make it work, in the meantime, any suggestions? Thanks in advance.

1 Answers
  location /en/ {
    rewrite /en(.+) $1 permanent;
  }

Makes a permanent redirect from /en/anything to /anything. This doesn't cover requests to yourdomain.com/en (without a slash at the end). If you like to fix that, add another location specifically for that case:

location = /en {
  return 301 https://$host/;
}
Related