Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

2 Answers 2

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 ^/$ http://example.com:8888/foo [R]

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

RewriteRule ^$ http://example.com:8888/foo [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
   ServerAdmin you@the.re

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

 ...
</VirtualHost>

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: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html

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

 
discard

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.