Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In chrome this configuration causes an infinite redirect loop and in every other browser I have tried a request for is resulting in a redirect to instead of however this only occurs when I do not include a trailing / at the end of the request url (i.e. works just fine).

<VirtualHost *:80>
    # ...

    RewriteEngine On

    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} ^/servlet(/.*)?$
    RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]

<VirtualHost *:443>
    # ...

    ProxyPass /servlet/ ajp://localhost:8009/
    ProxyPassReverse /servlet/ ajp://localhost:8009/

The virtual host on port 443 has no rewrite rules that could possibly causing the problem, the tomcat contexts being referenced do not send any redirects, and if I change the ProxyPass and ProxyPassReverse directives to:

    ProxyPass / ajp://localhost:8009/
    ProxyPassReverse / ajp://localhost:8009/

everything works fine (except for the fact everything from is being passed to the proxy which is not the behaviour I want). I'm fairly certain this is a problem with the way I have my proxy settings configured because I did log all the rewrite output coming from apache and it was all correct.

share|improve this question
put it in the answer then and accept it, you'll earn a self-learner badge ;) – Aleksandar Ivanisevic Mar 25 '10 at 21:19
up vote 0 down vote accepted

Switching from mod_proxy_ajp to mod_proxy_http seems to resolve this problem.

ProxyPass /servlet/ http://localhost:8080/
ProxyPassReverse /servlet/ http://localhost:8080/

Unfortunately this has the side effect of not passing along the ip address of the remote connection. Another alternative is to add a rewrite rule to match the url with the missing slash at the end:

RewriteCond %{REQUEST_URI} ^/servlet/[^/]+$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}/ [R=301,L]
share|improve this answer

I'm not sure if this is your problem, but ProxyPassReverse doesn't work with the ajp: url. ProxyPassReverse causes rewrites of Location: headers if they match. The headers generated by a redirect have http: URLs, not ajp:

You should be able to use:

ProxyPass /servlet/ ajp://localhost:8009/
ProxyPassReverse /servlet/ http://hostname/

i.e. use ajp: for the proxy to tomcat, but use http: for matching and rewriting the redirect headers. The returned headers also likely have the real hostname of the server instead of localhost. ( although localhost works for ProxyPass ). You can check the returned headers with 'curl -I ' to see what you need to match.

See this answer in stackoverflow for some links.

( This question is a couple of months old, but I just ran into the same problem, and had a tough time searching for the anwser. )

share|improve this answer

Your Answer


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.