I just created a new structure for a website, and I need some help on redirecting to new places.
The code that works is here, but I guess this can be optimized a lot.
location = /nl {
rewrite ^ $scheme://$server_name permanent;
}
location = /nl/ {
rewrite ^ $scheme://$server_name permanent;
}
location = /en {
rewrite ^ $scheme://$server_name permanent;
}
location = /en/ {
rewrite ^ $scheme://$server_name permanent;
}
location = /nl/contact {
rewrite ^ $scheme://$server_name/contact/ permanent;
}
location = /en/contact {
rewrite ^ $scheme://$server_name/contact/ permanent;
}
Rewrites don't have to be in location blocks - and can match against a regex.
You may have some success with two rewrites:
Alternatively, you can combine the first 4 and last 2 location blocks with regex matches - but that does chance the matching priority (which may not be very significant).
(Credit to @Saif Bechan for fixing my original proposition)