Aug 10, 2011
tom

Why do some rewrite rules fail while AJP is serving all of my requests to Tomcat?

Question

I have a Apache server using mod_proxy_ajp to have Jboss/Tomcat5.5 handling all the requests. Here is how I configured Apache 2.2.17, and for the most part, it works:

# Proxy pass all work to Tomcat, mod_jk 1.2.31
<Location />
    # ProxyPass / http://localhost:8080/
    ProxyPass ajp://localhost:8009/
    ProxyPassReverse ajp://localhost:8009/
</Location>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
#  and , to handle the redirect of the root dir
Redirect permanent / https://%{HTTP_HOST}%/myapp

Unfortunately, while ProxyPass is enabled, I am not able to get any mod_rewrite rules to work except for the ones above. How do I handle this situation?

I am trying to create a rewrite rule similar to this RedirectMatch rule (which only works if I turn off ProxyPass):

RedirectMatch ^/(?i)myagency   "/myapp?agency=MyAgency%20LA"

Also, another wierd thing I found, which may provide insight to my issue, is posted here .

Answer

You could convert your ProxyPass and ProxyPassReverse directives to RewriteRule directives instead, using [P] to proxy the request, like so:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteRule (.*) ajp://localhost:8009/$1 [P]

Related posts:

  1. How does Apache mod_proxy_ajp work when Jboss runs as a cluster with AJP on 2 different ports?
  2. Question about the syntax of the ProxyPass directive
  3. Apache mod_jk serves JSP through HTTP but fails to server JSP via HTTPS protocol?
  4. am i adding mod_proxy on CentOS with tomcat/apache correctly?
  5. Apache rewrite multiple conditions

Leave a comment