Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 0 down vote accepted

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%5Frewrite.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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.