Friday, January 27, 2012

Apache HTTPD Redirect Root URL to Sub Context / Directory

Yesterday I had to front an application running on Tomcat with Apache HTTPD server and one of the requirements was to automatically redirect the root URL to the Tomcat's web app context

e.g. to

Sounded pretty simple and did a Google search, went through few pages that had examples on how to do it but none of them worked. Most involved .htaccess files and using RewiteCond /RewriteRule combinations.

I was getting frustrated with finding a simple solution for the simple problem and after about an hour of searching and trying things I finally found the simple solution that worked. All it needed was the following single line in your VirtualHost section.

RedirectMatch ^/$ /application/

That's it and it will redirect all requests to root URL to the specified sub directory or sub context.

Don' forget to click the +1 button below if this post was helpful.


Antoine Philibert said...

Thank you!! So simple and so hard to find a solution!! :)

刘研 said...

after I add this to config file of apache httpd, the homepage is redirected recursively, and end with error. (environment: CentOS 6.5, Apache HTTPd 2.2.15, mod_jk 1.2, Apache Tomcat 7.0.53)

cmh said...

First hit on my search and it did exactly what I wanted, thank you so much!

Patrick Co Eban said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java EE Online Training from India . Nowadays Java has tons of job opportunities on various vertical industry.