STEP 1:
in C:\xampp\apache\conf\httpd.conf uncomment the following line:
- Code: Select all
LoadModule vhost_alias_module modules/mod_vhost_alias.so
STEP 2:
replace the content of C:\xampp\apache\conf\extra\httpd-vhosts.conf with the following
- Code: Select all
# get the server name from the Host: header
UseCanonicalName Off
# this log format can be split per-virtual-host based on the first field
LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
CustomLog logs/access_log vcommon
# include the server name in the filenames used to satisfy requests
VirtualDocumentRoot "C:\\xampp\\htdocs\\WORK\\%0\\docs"
VirtualScriptAlias "C:\\xampp\\htdocs\\WORK\\%0\\cgi-bin"
STEP 3:
Create C:\xampp\htdocs\WORK
STEP 4:
Restart Apache
Now setting a new vhost for a new project is a bit easier - no need to edit vhosts config and no need to restart apache:
1. Put a new domain record line in C:\WINDOWS\system32\drivers\etc\hosts , e.g.
- Code: Select all
127.0.0.1 example.loc
2. Create a folder with the name of the new created domain in C:\xampp\htdocs\WORK, e.g. C:\xampp\htdocs\WORK\example.loc
3. Create "docs" folder in the new folder, e.g. C:\xampp\htdocs\WORK\example.loc\docs . It's the document root folder for example.loc vhost.
These 3 things could be done by running the following batch file with the domain name as a parameter. I put it in c:\xampp\addvhost.bat, e.g.
- Code: Select all
addvhost.bat newexample.loc
addvhost.bat:
- Code: Select all
echo creating folders for %1
mkdir c:\xampp\htdocs\WORK\%1
mkdir c:\xampp\htdocs\WORK\%1\cgi-bin
mkdir c:\xampp\htdocs\WORK\%1\docs
echo adding %1 to windows hosts file
echo # >> C:\WINDOWS\system32\drivers\etc\hosts
echo 127.0.0.1 %1 >> C:\WINDOWS\system32\drivers\etc\hosts
echo %1 vhost added. test it.
Hope it was useful.