Windows HOSTS file and a particular server folder

apache-2.2hosturlwindowsxampp

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:

127.0.0.1       domainA
127.0.0.1       domainB

But what I would like is

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

How can I achieve this?

Tests

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]
RewriteRule ^/(.*)         http://127.0.0.1/domainA/$1 [L,R]

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

eg. http://127.0.0.1/ points to /htdocs

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

Solution

Add to apache httpd.conf the next lines:

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

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

Best Answer

Second answer :

You must use apache virtualhost capabilities :

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

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

vhosts docs

Related Topic