Use case
Our current frontend app was accessible by multiple domains:
https://boat.com (or https://www.boat.com)
https://car.com
https://plane.com
...
Each domain, was rendering the same app with different content and theme based on the domain name.
We are now trying to merge everything under one unique domain. So instead of accessing the site using its previous domain:
https://car.com
we want to access it using the following url:
https://common.com/car
On the code, we already took care of changing the logic to deliver the correct content based on this new routing system.
Problem
We want to redirect automatically our users to the correct routes when they try to access the app from an old domain. Example:
https://boat.com => redirect => https://common.com/boat
https://car.com => redirect => https://common.com/car
...
but we also want to be able to rewrite more complex url:
https://boat.com/categories/name-1 => redirect => https://common.com/boat/categories/name-1
https://car.com/posts/super-title-2 => redirect => https://common.com/car/posts/super-title-2
Is there a way to achieve it using NGINX dynamically/programmatically without having to write and repeat rules for each domains ?