Subdomain not linking with folder

joshuahornby10 asked:

The subdomain is working and connecting to my website but linking to the root and no the folder I thought I was linking to.

<VirtualHost *:80>
DocumentRoot /var/www/html/backend
ServerName www.teach.joshhornby.co.uk
<Directory /var/www/html/backend>
Allow from all
Options +Indexes
</Directory>
</VirtualHost>

I have checked the file structure and the file is located here
file:///var/www/html/backend

My answer:


OK, so you have two problems here.

The first problem is that the hostname you referenced in your ServerName doesn’t exist in the DNS. A different hostname does exist, though…

$ host joshhornby.co.uk
joshhornby.co.uk has address 141.101.116.48
joshhornby.co.uk has address 141.101.117.48
$ host teach.joshhornby.co.uk
teach.joshhornby.co.uk has address 192.30.32.208
$ host www.teach.joshhornby.co.uk
Host www.teach.joshhornby.co.uk not found: 3(NXDOMAIN)

The second problem is that you specified a different hostname in the ServerName field than you are using in your web browser. While Apache is expecting www.teach.joshhornby.co.uk, you are using teach.joshhornby.co.uk. Since Apache doesn’t know what to do with those, it punts, and you get your default virtual host.

To resolve the issue:

  1. Add a DNS record for www.teach.joshhornby.co.uk.

  2. Add ServerAlias teach.joshhornby.co.uk to your virtual host.


View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.