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 a virtual host in apache which is redirecting requests to another web server.

<VirtualHost *:80>
    DocumentRoot /var/www
    ServerName another.host
    ProxyPass        /  http://another.host2:8081/
    ProxyPassReverse /  http://another.host2:8081/
</VirtualHost>

I need to exclude an URL pattern from being catch by this virtual host. Basically I don't want requests with the url: http://another.host:8081/~username to be forwarded to the other server.

Can this be done?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Yes and no.

No in that you cannot exclude something from matching the VirtualHost; anything that matches the host name will always be attached to that VirtualHost.

Yes in that you can get the behavior you want, by having your ProxyPass happen only in locations that you don't want to serve locally.

Try something like this:

<VirtualHost *:80>
    DocumentRoot /var/www
    ServerName another.host
    <Location />
        Order deny,allow
        Allow from all
    </Location>
    <LocationMatch "^/[^~]">
        ProxyPass        /  http://another.host2:8081/
        ProxyPassReverse /  http://another.host2:8081/
    </LocationMatch>
</VirtualHost>
share|improve this answer
1  
I completely understand the solution and agree with it. My problem is now that the expression in the LocationMatch is not being treated as a regular expression. Any ideas why? –  Joao Trindade Mar 17 '11 at 16:31
1  
@Joao Well, I had screwed up the regex; I had it trying to match the ~username directories for proxying, instead of ignoring them. I've edited the answer, try now? –  Shane Madden Mar 17 '11 at 16:53
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.