2

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]

OR

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

OR

Using JKMount -

JkMount /MyApp/* ajp13
JkMount /MyApp* ajp13

OR

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.

Simon Hayter
  • 33,097
  • 7
  • 60
  • 119

2 Answers2

1

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

Simon Hayter
  • 33,097
  • 7
  • 60
  • 119
matthew
  • 398
  • 2
  • 8
0

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
</VirtualHost>

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.

Stephen Ostermiller
  • 99,822
  • 18
  • 143
  • 364