Forum Moderators: phranque

Message Too Old, No Replies

proxy ajp and URl rewriting?

         

the_poi

7:55 pm on Aug 17, 2006 (gmt 0)

10+ Year Member



I'm running a tomcat server and am currently passing requests from host.com/base2/ to it with the following entry in a .conf:

ProxyPass /base2/ ajp://localhost:8009/base2/

However, when the address of host.com/base2 is used, I get a file not found. This is expected, but I'm not sure how to fix the trailing slash problem while using proxy_ajp, as it's not a directory. In the same vein, I'd like to rewrite [host.com...] (or /base2/) requests to https:// . Again, I can do this with a directory, but not sure what needs to be done for use with the proxy. So basically, how can I rewrite every request to https:// and make the proxy work for a request with no trailing slash? Thanks for any pointers!

jdMorgan

1:46 pm on Aug 18, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You could either proxy both slash and non-slash requests to the back-end:

ProxyPass /base2 ajp://localhost:8009/base2

or treat it as a simple missing-slash problem and redirect:

RewriteRule ^/base2$ http://www.example.com/base2/ [R=301,L]

or treat it as a missing-slash problem and do an internal rewrite, as long as mod_rewrite executes *before* mod_proxy on your server:

RewriteRule ^/base2$ /base2/ [PT,L]

I suspect that the first (and simplest) solution would be best, since you say "it's not a directory," and the second two options are merely compensating for the fact that your ProxyPass [httpd.apache.org] directive included a trailing slash -- which it shouldn't if 'base2' is simply an extensionless file rather than a directory.

Jim

the_poi

7:27 pm on Aug 23, 2006 (gmt 0)

10+ Year Member



Thanks for the reply. I tried that first solution as soon as I noticed it, but it wasn't working--turns out I was adding an extra slash to the second part of the directive, works right now! Here's what I ended up with:

ProxyPass /base2 ajp://localhost:8009/base2
ProxyPass /base2/ ajp://localhost:8009/base2/
<Proxy *>
RewriteEngine on
Order allow,deny
Allow from all
RewriteCond %{SERVER_PORT}!^443$
RewriteRule ^.*$ [%{SERVER_NAME}%{REQUEST_URI}...] [L,R]
</Proxy>

Works perfectly!

jdMorgan

9:14 pm on Aug 23, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should carefully consider the use of the 302, rather than 301 redirect. The 302 tells clients (including search engines) that the new URL is temporary. Therefore, they will not update their URL database, and the content at the redirected address will be ascribed to the redirecting address.

Jim