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

share|improve this question
add comment

2 Answers

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.

share|improve this answer
add comment

For a reverse proxy, fixing the links in your content output (as mentioned in the other answer) is the better way to go, however mod_proxy_html is another possibility.

That said, if you're serving both applications out of the same Apache server why bother with the two virtual hosts? You should be able to serve two different languages from the same virtual host, that way you can skip the reverse proxy step completely.

share|improve this answer
    
Oh ok! thanks, Could you tell me where to read to learn how to serve two applications with differents languages in the same virtual host? –  Rafael Aug 26 '11 at 6:24
    
Pretty much the same way you do it for one. Just use <Location> and <Directory> as necessary to isolate the settings for each and use your rewrite rules to route the request to the correct app entry points. –  matthew Aug 26 '11 at 14:16
add comment

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.