问题
I have a number of applications running in Tomcat. Every one has its own context. I hooked them all to different domain names with Apache HTTP Server and mod_jk
(see more details at this question: How to mount context-referenced Tomcat application with mod_jk?). Works fine, but when applications generate their web pages all URLs still have their contexts:
http://www.example.com/
goes tohttp://www.example.com:8080/my-context/
http://www.example.com:8080/my-context/
produces a web page- The web page contains URL
/my-context/some-page.jsf
I would like to see /some-page.jsf
in the third step. What's important to notice is that I can't change application internals. They are provided by third parties. All I can do is to configure Tomcat or Apache HTTP Server.
回答1:
This is getting a bit complicated, but you can use a URL rewriter such as tuckey to rewrite outbound URLs, removing the /my-context prefix (by "outbound URLs" I mean URLs being generated inside your webapp(s)). Check out the documentation for the element at http://urlrewritefilter.googlecode.com/svn/trunk/src/doc/manual/3.2/index.html.
To make tuckey work with your webapp, you would need to add declarations to your apps' web.xml. Technically this means "modifying the applications", but it is minimally invasive. If you can't even touch the web.xml for some reason (not sure why), I seem to recall a way to externally impose a filter (not a valve) on a webapp in Tomcat, but that's going pretty far.
来源:https://stackoverflow.com/questions/5165781/how-to-hide-application-context-in-its-url-with-tomcat