Can apache redirect to another port without displaying the port?
August 16, 2006 12:58 PM   Subscribe

I'm not too well versed in Apache, and I'm having problems finding out if I can do what I want to do: Is there a way to use mod_rewrite to redirect a certain URL to a different port on the same sever without changing the URL displayed to the user? Example: Say I want http://myserver/tomcat to redirect to http://myserver:8080, but still keep the URL as http://myserver/tomcat. I've figured out how to do it so it changes the URL, and that seems to be touted as a "feature" of mod_rewrite in the documentation, but I can't find a way to turn it off. Is it possible? If not though mod_rewrite, then maybe some other module?
posted by emptybowl to Computers & Internet (10 answers total) 1 user marked this as a favorite
 
Response by poster: A more specific example, here's what I have in httpd.conf:


RewriteEngine on
RewriteRule ^/python(.*) http://myserver:9180$1


That properly redirects to 9180, but changes the URL to myserver:9180, while I'd like it to stay as /python
posted by emptybowl at 1:02 PM on August 16, 2006


If it isn't Apache running on the other port, then I'm pretty certain the answer is no. Probably the only way to do this is to set Apache up as a proxy server.
posted by cillit bang at 1:12 PM on August 16, 2006


cillit bang is probably correct. What you want is a proxy, not a rewrite.
posted by ijoshua at 1:25 PM on August 16, 2006


Response by poster: So, I would use the mod_proxy module?
posted by emptybowl at 1:25 PM on August 16, 2006


I believe that you can't do what you're asking. If you change the host or the port, you're no longer doing the redirect within the same Apache, so it automatically does an external redirect (make the browser request the new page), and the visible URL therefore changes.

Possibilities: use frames! Or a proxy server. You could code up a very simple proxy in PHP in about ten lines of code, put that on your original server, and redirect requests (internally) to it - it would silently fetch the pages from the :9180 server and return them to the user, who would be none the wiser.
posted by jellicle at 1:33 PM on August 16, 2006


Yes, mod_proxy should do what you want.
posted by Acetylene at 1:35 PM on August 16, 2006


If you had mod_proxy, mod_rewrite can do this:

RewriteEngine on
RewriteRule ^/python(.*) http://myserver:9180$1 [P]

See Rewrite Flags.
posted by revgeorge at 1:49 PM on August 16, 2006


ProxyRequests Off
ProxyPass /tomcat http://myserver:8080
ProxyPassReverse /tomcat http://myserver:8080
posted by slhack3r at 2:05 PM on August 16, 2006


There are some amazing cheat-sheets over on I Love Jack Daniels. (Really, I promise!)

The mod_rewrite is 4th from the bottom, and I have it taped to my wall right now.
posted by hatsix at 2:34 PM on August 16, 2006


You're using Tomcat with Apache? Why can't you do mod_jk with a connector? This allows you forward certain URLs to Tomcat through Apache/mod_jk, while letting Apache handle the other stuff. It would get rid of the port numbers.

Unless, of course, it isn't Tomcat behind the scenes...
posted by sbutler at 2:48 PM on August 16, 2006


« Older Any Good Poker Software?   |   What guns should I rent at an indoor range? Newer »
This thread is closed to new comments.