0

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 - https://serverfault.com/questions/235311/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?

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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