DNS mapping to subfolders
Asked Answered
P

3

5

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.

Paganism answered 7/6, 2012 at 7:42 Comment(1)
Could you please show your DNS records at www.example.com and test.com that implement your initial setup?Heliopolis
N
3

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.

Nic answered 14/6, 2012 at 23:51 Comment(0)
K
2

What you ask for called URL forwarding, and not DNS records. DNS records point to IP addresses or to another DNS records and test.com/abcd is neither of these. test.com is a domain name (DNS record), test.com/abcd is not a domain name, but it is an URL.

Kreager answered 7/6, 2012 at 12:24 Comment(0)
S
2

No you can't do this with DNS directly. DNS can only map to an host, but not path / port.

You will need a web server to redirect by HTTP 301. If you have access to edit your DNS record here is an easy one. You can also setup your own Apache / IIS if you are familiar with those rules.

Just remember HTTP 301 is a must to redirect otherwise your pageranks can't be transferred completely

Selfsatisfaction answered 17/7, 2012 at 9:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.