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.

I have a website on localhost, mapped in HOSTS as:

127.0.0.1 www.yorkshiretestingwebsite.com

127.0.0.1 yorkshiretestingwebsite.com

However, the folder (C:/www/vhosts/yorkshiretestingwebsite.com) has some sub-folders in it, namely:

leeds

hull

sheffield

and rather than typing in

http://www.yorkshiretestingwebsite.com/leeds

I would like to try and have the URL as:

http://leeds.yorkshiretestingwebsite.com

I've had a look for how to do this on Google, but am not quite sure how to do this.

I tried the advice here - Automatic subdomain creation in htaccess on Apache - and it did work (good if I only have a few folders) but what if I have multiple ones? I don't want to keep adding them to it, so I've been trying to find a solution.

What's the best way to achieve this?

share|improve this question

1 Answer 1

You'll want to create a new VirtualHost which will serve up the subdomains dynamically based on the directory tree:

<VirtualHost *:80>
    ServerName wildcard.yorkshiretestingwebsite.com
    ServerAlias *.yorkshiretestingwebsite.com
    VirtualDocumentRoot "C:/www/vhosts/yorkshiretestingwebsite.com/%1"
    ... (logging, permissions, etc) ...
</VirtualHost>

The %1 uses the first block of the name, so leeds.yorkshiretestingwebsite.com will point to C:/www/vhosts/yorkshiretestingwebsite.com/leeds/

More info on the VirtualDocumentRoot directive can be found here.

share|improve this answer

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.