Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We have one static IP on which we have routed our company website. We have setup a local machine on windows with WAMP to run our testing server.

We want virtual hosts to test our different apps. However, when creating subdomains, we have a new project which uses wildcard subdomains. How can we create the wildcard subdomains in VirtualHosts.

We use,

 NameVirtualHost *

<VirtualHost *>
    ServerAdmin admin@test
    DocumentRoot "E:/Wamp/www/corporate"
    ServerName  companysite.com
</VirtualHost> 

<VirtualHost *>
    ServerAdmin admin@test
    DocumentRoot "E:/Wamp/www/project"
    ServerName  project.companysite.com
</VirtualHost>

<VirtualHost *>
    ServerAdmin admin@test
    DocumentRoot "E:/Wamp/www/project"
    ServerName  *.project.companysite.com
</VirtualHost>

However, the last * wildcard does not work. Any help?

share|improve this question

migrated from stackoverflow.com May 30 '11 at 18:53

This question came from our site for professional and enthusiast programmers.

add comment

3 Answers

up vote 0 down vote accepted

I hope you are using this instead, and the above is just shorthand:

NameVirtualHost *:80
<VirtualHost *:80>
...

Then...

ServerAlias works with wildcards...

<VirtualHost *:80>
    ServerAdmin admin@test
    DocumentRoot "E:/Wamp/www/project"
    ServerName  www.project.companysite.com
    ServerAlias *.project.companysite.com
</VirtualHost>

Though you might have other configuration issues that could cause this to not take effect. I know WampDeveloper is set up for this to work, XAMPP probably too. Could try one of them.

share|improve this answer
    
Yes, server aliases worked perfect. Thank you for that. –  Khuram May 31 '11 at 4:36
    
@Khuram, please mark this as the answer so others with a similar issue know what to do. –  rightstuff May 31 '11 at 12:56
add comment

Here's the syntax for ServerName:

It doesn't mention that it supports any sort of wilcard.

The only way to have a "default" host is to use the fact that Apache will load the first <VirtualHost> block when there isn't any ServerName directive that matches the Host header.

share|improve this answer
    
Hi, we have several projects of this nature with multiple wildcard domains. If we make one of them default then other might not load? Thoughts? –  Khuram May 30 '11 at 11:56
add comment

If it helps anyone else who may stumble upon this question there is a simple step-by-step tutorial on setting up subdomains and virtual hosts for Wamp here: http://www.itutorblog.com/2011/06/how-to-create-a-subdomain-on-wamp/

share|improve this answer
    
Welcome to Server Fault! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. –  Chopper3 Jun 25 '11 at 10:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.