Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

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.

share|improve this answer

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]

share|improve this answer
    
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 host1.com/host2. I want this part to be behind the scenes, the user should see only 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 7:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.