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
JavaRanch » Java Forums » Products » Tomcat
Bookmark "tomcat and apache and mod_rewrite" Watch "tomcat and apache and mod_rewrite" New topic
Author

tomcat and apache and mod_rewrite

Stan Lederer
Ranch Hand

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

solrsandbox:8080/servlet/SolrSearcher

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

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

solrsandbox/myapp/science.html

Rewritten as:

solrsandbox:8080/servlet/SolrSearcher?userParam=science

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
Marshal

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

http://httpd.apache.org/docs/current/rewrite/flags.html#flag_p


Ping & DNS - my free Android networking tools app
Stan Lederer
Ranch Hand

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

http://httpd.apache.org/docs/current/rewrite/flags.html#flag_p


Awesome! That worked. Thank you VERY much.
 
 
subject: tomcat and apache and mod_rewrite