Q1: I have an existing API that uses the format https://sub1.domain.com/whatever?test=yes on sub1 subdomain, but now I want to switch over to the sub2 subdomain and a format like https://sub2.domain.com/v2/page/embed?new=1
The old requests should still work but be "forwarded" or "redirected" to the new request format and different subdomain. Ideally, this would happen seamlessly (transparently behind-the-scenes) and not require cURL to follow redirects, unless it is unavoidable.
Q2: Alternatively, I could compromise on replying to API requests for https://sub1.domain.com/whatever?test=yes using the same format but "forward" or "redirect" to the new subdomain like https://sub2.domain.com/whatever?test=yes
The point being that 25,000+ users with legacy format would not have to update their code to end up being served from the new server on sub2, and preferably using the new format (eliminating the need to maintain two sets of API parameters).
Appreciate your support on this. Thanks!
UPDATE:
I could find the answers myself. This will help someone in future.
For Q1:
location / {
if ($arg_test ~* yes) {
return 301 https://sub2.domain.com/v2/page/embed?new=1;
}
}
For Q2:
location / {
if ($arg_test ~* yes) {
rewrite ^(.*)$ https://sub2.domain.com$1;
}
}
You can use:
I could find the answers myself. This will help someone in future.
For Q1:
For Q2: