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've a domain on which I'm running two different web applications at different ports.

  • A Java web application on example:8888/foo
  • A PHP website on example:8080/bar

The requirement is, if an user tries to access the root of example:8888 or example:8080, then the user should be redirected to example:8888/foo.

How can I achieve this requirement?

share|improve this question

You can add the port in a redirect (or in any URL) by adding a colon and you can match the root of the site by using regular expressions in a RewriteRule.

RewriteRule ^/$ [R]

Inside a .htaccess file there are no leading slashes so this would be more appropriate:

RewriteRule ^$ [R]
share|improve this answer

I would put the JAVA application up with either mod_proxy, or mod_proxy_ajp. The later in case a.) this is a tomcat (compatible application server) and b.) you have access to the configuration of the application server.

NameVirtualHost *:8888
Listen 8888

<VirtualHost *>
   ServerName example

   <Location />
     <IfModule mod_proxy.c>
       ProxyPass http://example:8888/foo
       ProxyPassReverse http://example:8888/foo


You have to take care that your server (Apache) doesn't relay proxy requests. Most distributions have this savely set by default, but double check it. The Apache docu is your friend:

Port 8080 is a different matter as this is served by your application server itself. If you want to have it handled by the Apache as well, you should deactivate Catalina (Tomcat webserver) and set it up to serve via AJP.

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.