Bikas Katwal
Bikas Katwal

Reputation: 2055

Remove application name and servlet mapping from URL

I am using Apache httpd and proxying requests to my Tomcat server where my application WARs are deployed.

Let's say I have application App and servlet URL pattern /servlet1 and domain name abc.com. So, when I forward request from my ROOT.war servlet to /App/servlet1, my URL changes to abc.com/App/servlet1, but I would prefer abc.com for a better user experience.

I know I could do this by re-nameing App to ROOT.war but that is not an option for me, as we already have a ROOT.war for another application.

Is it possible to rewrite abc.com/App/servlet1 to abc.com other then ROOT.war? If so, how do I do it?

Upvotes: 0

Views: 597

Answers (1)

Christopher Schultz
Christopher Schultz

Reputation: 20882

The way to do this is to merge your ROOT and App applications together into a single application.

No servlet contains is going to be able to detect when some URLs should go to one application and others should go to another without some obvious mapping strategy. The servlet specification uses mandates the use of URL prefixes (context paths) to differentiate between deployed web applications: you cannot mix them together unless they are in fact the same application.

There are very very ugly ways to do this, but those techniques end up opening up a whole lot of headaches and continued hacks just to get around what sounds like a senseless requirement: making URLs pretty. Nobody cares how pretty a URL is. Make sure that example.com takes the user to the right place and don't worry about any of the rest of it.

Upvotes: 2

Related Questions