DNS mapping to subfolders

Aditya picture Aditya · Jun 7, 2012 · Viewed 25.4k times · Source

I have a use case where I have DNS domain with name www.example.com which points to test.com/abcd .

Now I want to create one more dns record which should point www.example.com/test2 to test2.com/abcd.

www.example.com is just a domain name and I dont have any server running on it.

Answer

Martin Thomson picture Martin Thomson · Jun 15, 2012

It sounds like you have a CNAME record like so:

www.example.com   CNAME   test.com

And code on test.com that performs a redirect, probably for all resources at www.example.com:

if (req.headers['Host'] === 'www.example.com') {
    res.writeHead(301, { 'Location': 'http://test.com/abcd' + req.url });
    res.end();
}

Since www.example.com is served by test.com, then you need to include another redirect on the server, which can either happen when clients land at http://www.example.com/test2 or when they land at http://test2.com/abcd/test2.