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 Apache running in a domain, for example http:// I also have Tomcat running on my server and I've forwarded all requests made to http:// to Tomcat and all other URLs are served by Apache directly.

My problem is I have a URL like http://, but I want tomcat to process that url, so it should actually point to http:// 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
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 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


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