Setting up a vhost allows you to use an alias of your localhost in your browser. For example, say that you want to work with a website which is normally located in http://localhost/example, but your script loads its assets from the root of the domain (in this example http://localhost/). This method allows you to load from the root of your document without needing to move your site files directly to http://localhost/.
This applies to both XP and Vista environments, and most likely all other Windows’.
The first thing you need to do is determine the alias you’re going to use. For example, if our site is located at http://localhost/example we may want to make an alias using http://example/. To do this, first open up your hosts file. Your hosts file contains aliases of network devices mapped to their IP addresses. To add a new one, just put in the IP address you want to map to (in the case of the local machine use 127.0.0.1), then some whitespace (tabs are nice), then the alias. To edit your hosts file, click Start | Run (or press Win+R) and type the following:
notepad C:\Windows\System32\Drivers\etc\hosts
Once you do this press enter and a notepad document will appear with the contents of your hosts file. Add the extra line detailed above. In this case, your file will look like the following (ignoring the comments at the top):
127.0.0.1 localhost 127.0.0.1 example ::1 localhost
Once you’re done, hit save and close the file. Vista may popup some UAC notice, hit ok. If you type http://example in your browser, it will take you to your http://localhost/ directory. We still need to configure apache/xampp to load the subdirectory.
To do this, open your vhosts file. To do this, you can open the run box like previously and type the following (depending on your xampp/apache installation directory)
notepad C:\xampp\apache\conf\extra\httpd-vhosts.conf
In this file, you’ll want to set up a localhost server and an example server (TIP: if you forget to set up localhost explicitly going to http://localhost will take you to the http://localhost/example directory). Make sure you backup the file first (copy and paste somewhere else) because if you make a typo in this file your Apache server may not start up properly after we restart it later.
Set up your file to look something like this:
NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot C:/xampp/htdocs ServerName localhost <Directory "C:/xampp/htdocs"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot C:/xampp/htdocs/example ServerName example <Directory "C:/xampp/htdocs/example"> Options Indexes FollowSymLinks Includes ExecCGI AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>
Once thats done, you’ll want to restart your Apache server. If you go to http://example/ right now, you’ll just see your normal http://localhost/ site. This is because the changes to your hosts file are immediate however the changes to Apache’s configuration files need to be re-read. To do this, open the run box again and type the following:
services.msc
Once you do that you’ll get a window where you can alter system services. Just select the option named Apache (in my case Apache2.2) and click Restart the service on the left side of the screen. This will restart Apache with the new settings. If you made a typo in your Apache vhosts configuration file, the server may not start properly.
Tags: Apache

Guess what? It doesn’t work on Apache…….
Despite
http://drupal
http://manual
127.0.0.1 localhost
127.0.0.1 manual
127.0.0.1 drupal
::1 localhost
always the same page is displayed
ServerAdmin webmaster@localhost
DocumentRoot “C:/Program Files/Apache Software Foundation/Apache2.2/manual”
ServerName manual
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride None
Options None
Allow from all
ServerAdmin webmaster@localhost
DocumentRoot “C:/Program Files/Rational/doc/help/licadmin”
ServerName drupal
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
FOUND THE PROBLEM
You forgot to mention UNCOMMENT the vhosts line. It has to be like:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
Mario,
The default configuration files for Apache as included in XAMPP and standard Apache will be different from each other, so when using this tutorial (or any tutorial) with different setups you’ll need to adapt the changes accordingly.
Glad to see it helped you out nonetheless.
Hey, Cheers for this post. Is quite helpful. I had this all working before with xampp, I have http://localhost working with two virtual hosts http://myclub.dev and http://mycharity.dev. It seems to be broken now with the config below, all *80 queries (localhost, mycharity and myclub) urls all go to ‘C:/xampp/htdocs/mycharity/dev/’ directory, beign for mycharity.dev vhost. If I rename all virtual hosts to instead of the below, all are redirected to ‘C:/xampp/htdocs’ being localhost directory.
NameVirtualHost *:80
ServerAdmin webmaster@localhost
DocumentRoot C:/xampp/htdocs
ServerName localhost
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
ServerAdmin webmaster@localhost
DocumentRoot C:/xampp/htdocs/mycharity/dev/
ServerName mycharity.dev
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
ServerAdmin webmaster@localhost
DocumentRoot C:/xampp/htdocs/myClub/dev/web_root/
ServerName myclub.dev
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
My hosts file is also valid at ‘C:\Windows\System32\Drivers\etc\hosts’.
127.0.0.1 localhost
127.0.0.1 mycharity.dev
127.0.0.1 myclub.dev
Any help is greatly appreciated.
/Paul
Thanks a lot. After enabling vhosts on XAMPP I was unable to see the xampp home page, always returning a 404 Error.
With your post, everything is working now. :) So, thanks a lot for sharing it.
K.R.
Márcio