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.

2 Answers 2

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]

3
  • hmmm. I was hoping reverse proxy would do it for me. Commented Mar 30, 2011 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 Commented Mar 30, 2011 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. Commented Mar 31, 2011 at 7:25

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.