Jump to content

Automatically route local sites to correct place


redbullmarky

Recommended Posts

Hi all

When working locally, I keep all my sites in a 'web' subdirectory, in a directory of their own. Each time I set up a new site, I have to add a line to my hosts.txt (eg, myproject.localhost) and also set up a vhost such as:

 

<VirtualHost *:80>
    DocumentRoot "D:/web/projects/myproject"
    ServerName myproject.localhost
</VirtualHost>

 

before restarting the server.

 

now, as I always follow the same pattern with naming, what i'm wondering - is it possible to wildcard the relevent places such that ALL requests to 'myproject.localhost' automatically know which correct DocumentRoot and ServerName to set up? Whilst it's not difficult to set up manually, it'd be much better for me if this was automated - apart from making it easier, it'd mean that any old sites wont require any tidying up of vhosts/hosts.txt file.

 

Cheers

Mark

Link to comment
Share on other sites

i may have posted a little quick for part of it. i managed to get apache set up with:

 

UseCanonicalName Off
VirtualDocumentRoot "D:/web/%1"

 

at the end of my vhosts file. however, i still need to add these to my hosts file. is it possible to automatically have all *.localhost requests go to my local webserver?

Link to comment
Share on other sites

The only was Ive found to avoid adding new sites to your hosts file is to setup a local DNS server. I'm not sure whats around for windows but Bind was a fairly straight forward setup on Linux.

 

Of course the other thing you could do would be simply to script the entire process. Then it could be as simple as...

 

addsite foo.localhost

 

Which would then create the vhost (Never been a fan of using VirtualDocumentRoot as you can't customise logging on a per site basis), restart Apache and add the entry to your hosts file.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.