CNAME is redirecting to my host page

499 Views Asked by At

I have a website hosted on the following path: mywebsite.com/test with the following DNS

mywebsite.com            A   1.2.3.4 (host ip)
host.mywebsite.com       A   1.2.3.4 (host ip)

On another domain I'm trying to make a subdomain CNAME redirect to this page using the following:

link.myotherdomain.com   CNAME .  mywebsite.com/test

However when I access link.myotherdomain.com it shows the host.mywebsite.com instead of mywebsite.com

I'm doing something wrong?

Thanks

1

There are 1 best solutions below

2
On

CNAME record cannot include path. It only for domin to domain. This setting will work.

link.myotherdomain.com.   CNAME   mywebsite.com.

If configured properly, all of mywebsite.com host.mywebsite.com link.myotherdomain.com are resolve to 1.2.3.4, then the following HTTP request is sent to IP address 1.2.3.4.

GET /test HTTP/1.1
Host: link.myotherdomain.com
......(omit)

Now, the most suspiicious element is the Virtual Host setting of webserver. This is a function of the web server that behaves as if it is a different server according to the Host value in the request header.

To survey about Virtual Host, the following might be the most simple method.

  • curl -H 'Host:mywebsite.com' http://1.2.3.4/test // this will ok
  • curl -H 'Host:link.myotherdomain.com' http://1.2.3.4/test // this will not ok if Virtual Host enabled