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 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.

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]