2

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 .

3 Answers 3

2

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] 
3
  • 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? Commented Apr 28, 2011 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 :) Commented Apr 29, 2011 at 1:46
  • I edited my question (above) to highlight the difference between http/mod_proxy vs. ajp/mod_proxy_ajp . Commented Apr 29, 2011 at 2:10
2

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 </Location> 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" 
-1
LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_ajp_module modules/mod_proxy_ajp.so LoadModule rewrite_module modules/mod_rewrite.so RewriteEngine On RewriteRule ^/$ /index.html [L] # RequestHeader set REMOTE_USER %{LA-U:REMOTE_USER}e RewriteCond %{REQUEST_URI} !^/fusioncp ReWriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteRule ^(.*) ajp://localhost:18009$1 [P] 

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.