Take the 2-minute tour ×

I have been playing around with the windows HOSTS file which seems to be located under c:\windows\ (Windows 95, 98 y Me), and under C\Windows\system32\drivers\etc\ in (Windows NT, 2000, XP and Vista)

I would like to point

http://mydomain/ to a particular folder of my web server. I Hosts file currently looks like:       domainA       domainB

But what I would like is

http://domainA/ points to
http://domainB/ points to

How can I achieve this?


To use the rewriteModule uncomment the next line in your httpd.conf file:

LoadModule rewrite_module modules/mod_rewrite.so

The next code does not what I was looking for.

RewriteEngine  on
RewriteCond %{HTTP_HOST}   ^domainA [NC]

With the above code when you type in your browser http://domainA/ it automatically changes it to but what I want it to stay in http://domainA/ while serving the content of the folder.

eg. points to /htdocs

I want http://domainA/ to point to /htdocs/domainA


Add to apache httpd.conf the next lines:

<VirtualHost *:80>
ServerName http://domainA/
DocumentRoot "/htdocs/domainA"

<VirtualHost *:80>
ServerName http://domainB/
DocumentRoot "/htdocs/domainB"
share|improve this question

3 Answers 3

up vote 3 down vote accepted

Second answer :

You must use apache virtualhost capabilities :

<VirtualHost *:80>
# url like
DocumentRoot /htdocs

<VirtualHost *:80>
# url like http://domaina/.....
ServerName domaina
DocumentRoot /htdocs/domaina

vhosts docs

share|improve this answer
Exactly what I was suggesting for IIS; +1 because I don't know Apache and you filled the gap. –  Massimo Aug 26 '09 at 13:35
This is what I did recently on an install of WAMP. –  Hondalex Aug 26 '09 at 21:53

The only purpose of the HOSTS file is mapping names to IP addresses; it doesn't have anything at all to do with URLS (the same is true for DNS). You just can't do that this way.

Other than rewriting URLs as suggested, you could also use host headers:

  • Define the two names in the HOSTS file and make them both point to
  • Define two websites in your web server, one which answers to "domainA" and the other one which answers to "domainB"

This way, when you call http://domainA, you will see the first web site; when you call http://domainB, the second one will show up; the web server will automatically recognize which name it's being called with and serve the appropriate web site, even if both are running on the same IP address.

If you want to use IIS, you need to be running a server version of Windows in order to create multiple web sites; IIS on client systems like XP and Vista only supports a single site.

share|improve this answer
host headers is a far simpler option than the rewriting route, although if you are stuck with using apache you don't have much choice other than to use a re-write –  Jim B Aug 26 '09 at 11:32
Why, can't Apache serve multiple web sites based on host headers? –  Massimo Aug 26 '09 at 11:53

You talk about two differents thinks :

  1. name resolution (dns, hosts file)
  2. url rewriting (transform an url)

you can't do url writing with your hosts file.

to do :

 http://domainA/ points to

You need use an url writing api on you web server :


Sample configuration for apache :

RewriteEngine  on
RewriteCond %{HTTP_HOST}   ^domainA [NC]

RewriteCond %{HTTP_HOST}   ^domainB [NC]
share|improve this answer
I am using xampp. So it is apache. Any quick tip? –  Sergio del Amo Aug 26 '09 at 11:08
I have rewritten my post to explain my problem better. Thanks for your help. –  Sergio del Amo Aug 26 '09 at 11:56
Add the apache tag to you question, you could have more answer :) –  Gayell Aug 26 '09 at 13:34

Your Answer


