3

I'm trying to map one virtual host to a subdirectory of another virtual host, something like this http://host2.com -> http://host1.com/host2. At this moment, whenever I go to http://host2.com it maps to http://host1.com instead of http://host1.com/host2

My default site file is this

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName "host1.com"

 <Directory /srv/www/host1>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride None
    Order deny,allow
    Allow from all
 </Directory>

 DocumentRoot /srv/www/host1
 WSGIScriptAlias / /srv/www/host1/apache/django.wsgi

 </VirtualHost>

<VirtualHost *:80>

    ServerAdmin webmaster@localhost
    ServerName "host2.com"
    DocumentRoot /srv/www/host1

    <Proxy *>
    Order deny,allow
    Allow from all
    </Proxy>

    ProxyPass / http://host1.com/host2
    ProxyPassReverse / http://host1.com/host2

</VirtualHost>

What am I missing? I'm not sure if it should matter, but I'm using Django with wsgi.

Neo
  • 265
  • 2
  • 6
  • 12

2 Answers2

3

This can actually be accomplished using a single <VirualHost />, by using the ServerAlias directive. You can then use the RewriteRule to pass those requests to the proper directory, and by leaving off [R] you will just be rewriting the request, leaving the URL intact.

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName host1.com
    ServerAlias host2.com

    <Directory /srv/www/host1>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order deny,allow
        Allow from all
    </Directory>

    DocumentRoot /srv/www/host1
    WSGIScriptAlias / /srv/www/host1/apache/django.wsgi

    RewriteEngine On
    RewriteCond %{HTTP_HOST} host2\.com [NC]
    RewriteRule (.*) /host2$1 [L]
</VirtualHost>

Hope this helps.

clmarquart
  • 436
  • 3
  • 5
0

Here's another post that might help: Redir

I haven't tested this below but you get the idea.

You could use redirecting:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www\.host2\.com [NC]

RewriteRule ^(.*)$ http://host1\.com\host2 [L,R=301]

Jonathan Ross
  • 2,173
  • 11
  • 14
  • hmmm. I was hoping reverse proxy would do it for me. – Neo Mar 30 '11 at 20:36
  • And in your solution the users will see new url, ie http://host1.com/host2. I want this part to be behind the scenes, the user should see only http://host.com – Neo Mar 30 '11 at 21:01
  • Ahh, I see. The only way I've preserved the URL in the browser Address Bar in the past is using a single pixel `.gif` image and a META REFRESH in HTML. – Jonathan Ross Mar 31 '11 at 07:25