Apache nested virtual hosts

apache-2.2mod-proxymod-rewritevirtualhost

I have two virtual hosts in a apache server and I would like to do something but I don't know if is possible.

The thing is that I have the main application developed and ruby and the blog is in wordpress. So right now I have something like this:

  • example.com and blog.example.com

What I would like to do is that all the request to www.example.com/blog are served by the blog.example.com, but without doing a redirects (i.e I don't want the user to see a change in the URL)

What I've tried so far is to do a proxy in the VirtualHost:

<Location  /blog>
    ProxyPassReverse http://blog.example.com
    ProxyPassReverse http://blog.example.com:80
    RewriteEngine On
    RewriteRule blog/(.*)$ http://blog.example.com/$1 [QSA,P,L]
</Location>

And it works, but once I'm in the other app all the links are inside blog.example.com and not in example.com/blog.

Do you know a workaround for this?

Thanks in advanced for your help.

Best Answer

Links are handled in your content, not by Apache. ProxyPassReverse only translates for redirects - everything else is on you.

Fix it by using host-relative paths in your content - instead of linking to http://blog.example.com/dir/page.html, link to /dir/page.html.

If the links are being dynamically generated by WordPress, then it's probably reading the host header; ProxyPreserveHost would be the normal way around this, but won't work with both vhosts being on the same listener - you'd end up feeding requests right back to the vhost that's doing the proxying.