Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

tomcat and apache and mod_rewrite

 
Stan Lederer
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stan Lederer
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic