LordZardeck
LordZardeck

Reputation: 8283

virtual hosts with subdomains not working

I have these two virtual hosts for my development server. I need to send any request to dev. or *.dev. to one application, which will handle dealing with the subdomains. Right now, only the second one works, with any request sent to *.dev. being passed to the application. But if I just go to the dev. subdomain, i get an error in my browser saying the page couldn't be found. What is going on?

<VirtualHost *>
    ServerName dev.redemptionconnect.com
    ServerAlias dev.redemptionconnect.com
    DocumentRoot "C:/xampp/htdocs/dev.redemptionconnect.com/"
</VirtualHost>

<VirtualHost *>
    ServerName sub.dev.redemptionconnect.com
    ServerAlias *.dev.redemptionconnect.com
    DocumentRoot "C:/xampp/htdocs/dev.redemptionconnect.com/"
</VirtualHost>

Upvotes: 0

Views: 2480

Answers (1)

Michael Berkowski
Michael Berkowski

Reputation: 270599

Edit: I assume you have defined the subdomain dev.redemptionconnect.com in DNS? I don't turn up an address for it.

# tournaments.dev. works....
PING tournaments.dev.redemptionconnect.com (107.21.224.129) 56(84) bytes of data.

# but bare dev. does not...
ping: unknown host dev.redemptionconnect.com

You'll need DNS records for the first subdomain and each of its sub-subdomains. Defining the sub-subdomains does not implicitly define their parent subdomain as well.

This may be because you are using dev.redemptionconnect.com in both the ServerName andServerAliasdirectives for the firstVirtualHost`, however I wouldn't expect that to cause an issue.

However, since you're pointing them both to the same application directory do you really need to VirtualHosts at all? You can just specify multiple ServerAlias:

<VirtualHost *>
    ServerName sub.dev.redemptionconnect.com
    # Multiple domains in ServerAlias
    ServerAlias dev.redemptionconnect.com *.dev.redemptionconnect.com
    DocumentRoot "C:/xampp/htdocs/dev.redemptionconnect.com/"
</VirtualHost>

Upvotes: 3

Related Questions