I have the domain example.com
and have set up the Ubuntu Apache server in a way that it points any subdomain to a directory with the same name.
<VirtualHost *:80>
ServerAlias *.example.com
VirtualDocumentRoot /var/www/html/%1
</VirtualHost>
So subdomain.example.com
will point to example.com/subdomain
.
I am trying to allow users point their own custom domain to a subdomain of their choice, how could I achieve this and what records would be required and what would have to be done to the Virtual Host?
I have tried the following record:
sampledomain.example
(CNAME record) -@
-->sample.example.com
sampledomain.example
(A record) -@
--> (IP
Address of example.com)
I have also tried using www
for the CNAME along with removing the A record
.
sample.example.com
successfully points to example.com/sample
. However, sampledomain.example
acts like the root site for some reason.
So if I visit sampledomain.example/sample
, I will get the contents of example.com/sample
rather than pointing to sample.example.com
.
How could I sort this out? Which records would be needed and what could be done to the Virtual Host?
I used a CNAME record so that I can retrieve the custom domain name via PHP when the user visits that - is the CNAME required?