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 apps on Tomcat that use URLs like this: http://xxx:8080/myapp

I don't want the users to see the port in the URL.

Hi can do a rewrite rule like this:

RewriteRule ^/myapp(.*) http://xxx:8080/myapp$1 [P,L]

This way, if a user goes to the URL http://xxx/myapp he can enter the app fine, but the port will still show up on the browser. I want the URL that the user sees to be always http://xxx/myapp

How can I do this using mod_rewrite?

share|improve this question
up vote 0 down vote accepted

You can use reverse proxy in Apache.

Create a VirtualHost which is listen on 80 port and setup proxy:

ProxyPreserveHost Off
ProxyPass / http://xxx:8091/app/
ProxyPassReverse / http://xxx:8091/app/
share|improve this answer
This was the solution I used. But, I used the rules like this: ProxyPass /webapp http://xxx:8080/webapp/ ProxyPassReverse /webapp http://xxx:8080/webapp/ With the generic rule ProxyPass / http://xxx:8091/app/ it conflicts with the hosts I had on Apache. – Gotcha Jun 4 '12 at 8:45

If you don't have any other web server listening on port 80 like apache, a simple solution will be to change the listening port of tomcat to be 80.

If you have apache listening on port 80, you can still access your apps on port 80 using mod_jk.

share|improve this answer

The best way to do this is via a reverse proxy.

You can setup another web server in front of tomcat that acts as a reverse proxy and automatically does the translations between port 80 at the front and port 8080 at the back.

Apache can be configured using *mod_proxy* or even *mod_jk* and/or *mod_proxy_ajp*. Otherwise, you can use standalone proxies such as pound.

share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.