0

I have Apache running in a domain, for example http:// example.com. I also have Tomcat running on my server and I've forwarded all requests made to http:// example.com/t/ to Tomcat and all other URLs are served by Apache directly.

My problem is I have a URL like http:// example.com/bar, but I want tomcat to process that url, so it should actually point to http:// example.com/t/bar. In other words, the URL should be processed by Tomcat which gets the application context "bar".

Problem is, I'm not quite sure how to make the proper rewrite rule for this. I tried adding this to sites-available/default

RewriteEngine on
RewriteRule ^/bar(.*) /t/bar$1 [R]

But that doesn't preserve the URL, and instead just redirects to the Tomcat URL with the /t/ prefix. If I remove the [R], then I just get a 404.

What is the proper RewriteRule to solve my problem?

Dave Drager
  • 8,375
  • 29
  • 45

2 Answers2

0

How are you processing Tomcat connections via /t/*? Is this via mod_proxy?

I think you may need to use mod_proxy or maybe mod_alias instead of a RewriteRule, since /t/ is not an actual directory on the apache server and instead forwards to something else.

Dave Drager
  • 8,375
  • 29
  • 45
0

You need to proxy it with the [P] option. This also will require you to set up mod_proxy.

See http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html and search for "force proxy".

Keep in mind that this will put additional load on your Apache. How much load is dependent upon how much traffic you receive and how quickly the Tomcat server can return traffic back to the Apache.

You could also just simply include /bar in your mod_proxy_ajp rules or mod_jk configuration (JkMount), which would be a far far better solution than using mod_rewrite.

Aaron Brown
  • 1,697
  • 1
  • 12
  • 22