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

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

share|improve this question
up vote 2 down vote accepted

Ok, I finally figured it out for myself. AJP protocol works differently than HTTP type rules and so they wouldn't mix. To solve it, I had to stop redirecting everything to AJP and instead just redirect the application only using AJP. Here was the answer:

# don't ProxyPass through the "/" dir location,
# since it breaks the mod_rewrite rules
<Location /myapp>
    ProxyPass ajp://localhost:8009/myapp
    ProxyPassReverse ajp://localhost:8009/myapp
RewriteEngine On
# rule to redirect from http to https
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
# rule to redirect /  to the app context since nothing is served at /
Redirect /  /myapp?name=
# supplemental rules to handle URI shortcuts
RedirectMatch ^/(?i)name1   /myapp?name=NameOne
RedirectMatch ^/(?i)name2   "/myapp?name=Name%20Two"
share|improve this 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]
share|improve this answer
Using the [P] option of mod_rewrite didn't work for me. The only way it will really proxy for me is by using the ProxyPass rule of mod_proxy_ajp . I think this makes sense since [P] was made for proxies in general, and not for the special case of AJP, right? – djangofan Apr 28 '11 at 22:25
I'm actually not positive, as I've never applied this to AJP specifically. I know that mod_rewrite actually uses mod_proxy to carry out its proxying. I kinda went out on a limb, and assumed that any functionality added to mod_proxy by mod_proxy_ajp (ie, handling ajp:// URLs) would also be gained by mod_rewrite and it's proxying. I'll do a little more poking around :) – walkeran Apr 29 '11 at 1:46
I edited my question (above) to highlight the difference between http/mod_proxy vs. ajp/mod_proxy_ajp . – djangofan Apr 29 '11 at 2:10
LoadModule proxy_module modules/
LoadModule proxy_ajp_module modules/
LoadModule rewrite_module modules/

RewriteEngine On
RewriteRule  ^/$  /index.html  [L]

# RequestHeader set REMOTE_USER %{LA-U:REMOTE_USER}e
RewriteCond %{REQUEST_URI} !^/fusioncp
RewriteRule ^(.*) ajp://localhost:18009$1 [P]
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.