aspose file tools*
The moose likes Tomcat and the fly likes tomcat and apache and mod_rewrite Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Tomcat
Bookmark "tomcat and apache and mod_rewrite" Watch "tomcat and apache and mod_rewrite" New topic

tomcat and apache and mod_rewrite

Stan Lederer
Ranch Hand

Joined: Sep 24, 2012
Posts: 35
I've got a server called solrsandbox. I've written a servlet which responds at this URL via tomcat:


I've got an apache httpd server responding on the default port 80.

What I'm trying to do is to have this URL:


Rewritten as:


without exposing the rewritten URL in the browser.

My first thought was to use mod_rewrite. I figured out the syntax, set up the rewrite rule and quickly discovered that because I'm rewriting the original URL to be one that Apache doesn't manage that, even though the redirect works, the new URL is displayed in the browser.

My next idea was to use mod_proxy which seemed like it should work but it, for some mysterious reason, stripped off the :8080 from the target rewritten address. Grumble grumble.

I could probably get this thing to work by creating a virtualhost container in Apache and proxying port 8080 to port 80 (and the reverse). But, both the original and the target URLs are on the same host so setting up a vhost seems overkill but I'll do it if there's no better way to do what I want.

I also considered writing a simple proxy server that would sit on port 80, send user input to the servlet and display the servlet's output to the user's browser. I imagine that would work fine but I'm not thrilled to introduce the overhead of a proxy to a potentially heavily-used servlet.

Am I missing something? Is there a simple way to do this rewriting/proxy stuff?

Thanks very much.
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 39537
mod_rewrite can be made to use mod_proxy via the [P] option; I think that's what you need here.

Ping & DNS - updated with new look and Ping home screen widget
Stan Lederer
Ranch Hand

Joined: Sep 24, 2012
Posts: 35
Ulf Dittmer wrote:mod_rewrite can be made to use mod_proxy via the [P] option; I think that's what you need here.

Awesome! That worked. Thank you VERY much.
I agree. Here's the link:
subject: tomcat and apache and mod_rewrite
Similar Threads
SSLEXT behavior-- rewrite works, page doesn't come up
Yet another Tomcat port question
DNS and Web Application Resolution
The requested resource is not available