I am trying to remove the context name from the URL of my server.

Current URL - http://www.domainname.com/MyApp/

What I need to make is to make it available at - www.domainname.com/

So it is only going to host one main app and that needs to be displayed when we open www.domainname.com/ on browser.

I have already tried couple of things like below -

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(Context/.*)$
RewriteRule ^/(.*)$ /Context/$1 [P,L]


redirect permanent /MyApp/ abcd://domainname.com


Using JKMount -

JkMount /MyApp/* ajp13
JkMount /MyApp* ajp13


Deploy war file to ROOT of tomcat and make relevant chagnes in web and server.xml All of these aren't working and I keep getting a intenal error. I need a way to basically trim the tomcat URL to make short.

  • Is there a link with "www.domainname.com/"? I mean do you plan to do other rewrite rules for other domains that will use your app too? – Olivier Pons Nov 19 '11 at 6:27

Assuming that http://www.domainname.com/MyApp/ works as is... shouldn't you be able to just use your final RewriteRule? Just drop the RewriteCond and the 'P' flag.

Or if you're going to use mod_rewrite to do the proxy with the 'P' flag, don't you need to use the full URL in the RewriteRule? Something like http://tomcatserver:tomcatport/Context/$1

| improve this answer | |
  • @matthew Thanks Matthew though I did try with following as per your suggestion though it doesn't seem to have worked out - RewriteRule ^/(.*)$ /Foldername/$1 [P] Instead of (.*), I used following - RewriteRule ^/(/.*)$ /GroupAGWeb/$1 [P] OR RewriteRule ^/(abc-xyz.paint-domain.com.*)$ /Foldername/$1 [P] – Redbull Fan Feb 18 '11 at 4:52
  • I don't think you want the P flag. If you've set up the Proxy with Mod_jk I don't think you also need to tell mod_rewrite to do the proxy. – matthew Feb 21 '11 at 12:38

You should stop using mod_jk and start using mod_proxy. I run tomcat on port 8080. The web app that powers my site has an internal url like http://localhost:8080/mysite I use mod proxy to make it available at http://mysite.example.com/ I use a firewall to ensure that only port 80 is accessible from the outside world. mod_proxy is much more flexible than mod_jk. Tomcat makes application available both http port 8080 and through the ports that mod_jk uses by default, so you likely won't even have to change your tomcat settings.

My apache configuration looks like this for that site

<VirtualHost *:*>
    Servername mysite.example.com
    ProxyRequests Off
    ProxyPass / http://localhost:8080/mysite/
    ProxyPassReverseCookiePath /mysite /
    ProxyPassReverseCookieDomain localhost mysite.example.com

The cookie stuff is so that session cookies get translated by mod_proxy correctly. You can also have mod_proxy rewrite the links if you need to. In my case, my web app handles that.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy