Could you explain in plain, non-technical terms what it actually is you want to achieve at the end of the day?
Sure!
a) User enters domainA.com and gets redirected to domainB.com;
b) domainB finds out which domain user was redirected from, and based on that does:
i) sends request to analytical software recording that ‘visit from domainA has happened’;
ii) is issueing another redirect to location(=domainC) x,y,z,d, etc. depending on the domainA value.
That ^ are the business requirements.
Could it be that you do not want to send a 301 back to the client, but actually proxy the request onward to B or C? In that case adding the referrer would make sense but you would need to include this in the new request object that you actually pass on to
fetch
.
I want the user to go domainA->301->domainB->301->domainC.
- Why do you fetch the original request if you send a 301 anyhow?
location
does contain a proper URL in your actual code, right? Because just a domain name wouldnt be valid.- Where does the
host
variable come from?
Goes those questions are not relevant anymore with the updated code examples.
In other words, how do I ensure that in “domainA->301 → domainB->301->domainC” the bolded arrow, which represents request sent by client after receiving 301 redirect, contains “domainA” in any form of the request. I imagine I could achieve this by issueing ‘set-cookie’ readable by both domains with 301 response, but I was expecting to achieve this with Referers.