Here's an example of how you can use match replacements in nginx redirect rewrite rules that can be used within a server
block:
Here's a complete example using the last one in the list on the staging site. So where you had:
rewrite (?i)^/en/pages/137-test-page$ $scheme://$host/en/pages/the-new-place permanent;
I've changed it to be:
rewrite (?i)^/(de/|en/|es/|fr/|it/|.?)pages/137-test-page$ $scheme://$host/$1pages/the-new-place redirect;
Hopefully you can see the regular expression part which is matching on any of the current language options on the site and no language at all - then note in the directed url the $1
this is the placeholder that will get replaced by the bit that matches in the first url so e.g. the first part matches:
fr/
It'll add that into the redirected url at the end point to rewrite it. Hopefully that makes sense and you can see how you'd need to convert each of the urls.
Finally, note that I've used redirect
at the end instead of permanent
. This is primarily for testing purposes but you may want to change that to permanent if it's to be a permanent redirection. The only thing to note is that since the existing rules are permanent then changing those might result in the redirects not necessarily doing what you'd expect because the browser will have cached them as permanent regardless of new rules. Obviously it all depends on what the clients asked for. If there's a chance that the redirects will be removed at some future point you're probably better off setting them as redirect
(302s) over permanent
(301s).