'Rewrite domains to subdirectories without changing url in Nginx

I have to move a website from an Apache to an Nginx environment, but it turns out rewrites are done differently here (which I'm not very familiar with).

The website has multiple language domains with a simple html page in a subdirectory for each language, and general subdirectory that should work for all domains.

So the setup is basically this:

But whenever for example www.domain.de/imagebank/ is called, it should ignore the /de/ and just get the content from /imagebank/ instead. Including the files that will be in there.

This is my current code in .htaccess, but it needs to be changed to Nginx:

RewriteRule ^imagebank - [L,NC] 

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTP_HOST} ^(www.)?domain.nl$
RewriteRule !^nl/ nl%{REQUEST_URI} [L]

RewriteCond %{HTTP_HOST} ^(www.)?domain.fr$   
RewriteRule !^fr/ fr%{REQUEST_URI} [L]

RewriteCond %{HTTP_HOST} ^(www.)?domain.de$   
RewriteRule !^de/ de%{REQUEST_URI} [L]

I put the above code in a converter, but I'm not sure how correct it becomes:

location ~ ^/imagebank { }

location / {
  if (!-e $request_filename){
    rewrite ^(.*)$ https://www.$http_host$request_uri redirect;
  }
  if ($http_host ~ "^(www.)?sagabadkamermeubelen.nl$"){
    rewrite !^nl/ /nl$request_uri break;
  }
  if ($http_host ~ "^(www.)?domain.fr$"){
    rewrite !^fr/ /fr$request_uri break;
  }
  if ($http_host ~ "^(www.)?domain.de$"){
    rewrite !^de/ /de$request_uri break;
  }
}

Would the above suffice or is there a better approach?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source