In my current scenario there are a dozen domains with a PHP redirect script set up on them that obtains the destination URL from a SQL database based on the $_SERVER['QUERY_STRING'] parameter passed in the URL initially requested by the User.
NginX is configured like this on each of these servers (which we'll call Domains_A/B/C):
location /r/ {
rewrite ^/r/(.*)$ /r/index.php?$1;
}
So the request goes like User > Domains_A/B/C > Destination URL
But what I would like is to not have to duplicate the PHP redirect script and keep this script on a single domain. This may be obtained by doing something like this:
Domains_A/B/C
location /r/ {
rewrite ^/r/(.*)$ https://Domain_X/r/index.php?$1;
}
Domain_X (with PHP redirect script)
location /r/ {
rewrite ^/r/(.*)$ /r/index.php?$1;
}
But this multiplies the redirects as User > Domain_A/B/C > Domain_X (with PHP redirect script) > Destination URL. And also the Referer sent to Destination URL is Domain_X which is something I am trying to avoid.
I would like to not multiply the redirects and to keep Domains_A/B/C as the Referer too. As in have NginX obtain the destination URL from Domain_X when Domains_A/B/C are accessed and point the redirect directly at the Destination URL from Domains_A/B/C.
Something along these lines on Domains_A/B/C:
location /r/ {
set Destination_URL get from https://Domain_X/r/index.php?$1;
rewrite ^/r/(.*)$ Destination_URL;
}
Is this possible? I was not able to find a solution yet.