我们有Tomcat 5.5和Apache 2.2 mod_proxy。 我们想要漂亮的url。 例如,这或多或less是我们的url现在的样子:
http://example.com/foo/app/home (home page) http://example.com/foo/app/bar (other parts of the web app) http://example.com/foo/api/qux (API hooks) http://example.com/foo/quux (misc)
我们希望公开的url更简单,例如:
http://example.com/ (home page) http://example.com/bar (other parts of the web app) http://example.com/api/qux (API hooks) http://example.com/quux (misc)
我知道如何让Apache将传入的URL重写为Tomcat使用的较长的URL,但是我担心这可能会混淆Tomcat。 我有相当的经验与Apache,但Tomcat的新手。
此外,我们想要重写,而不是redirect(例如, http : //example.com/不应该简单地redirect到http://example.com/foo/app/home ),因为我们要保持丑陋完全地址栏外的URL。
如果你把所有东西都重写到一个普通的位置,你通常会这样做:
ProxyPass / http://localhost:8080/foo/ ProxyPassReverse / http://localhost:8080/foo/
如果你需要不同path的不同规则,你可能会在一系列RewriteRules上使用Proxy标志:
RewriteRule /bar/(.*) http://localhost:8080/foo/app/bar/$1 [P] RewriteRule /api/qux/(.*) http://localhost:8080/foo/api/qux/$1 [P] RewriteRule /quux/(.*) http://localhost:8080/foo/quux/$1 [P] RewriteRule /(.*) http://localhost:8080/foo/app/$1 [P]
这将把东西发送到Tomcat的适当位置。
唯一的麻烦是如果应用程序dynamic生成具有完全限定path的URL。 在这种情况下,您需要修复应用程序,或使用类似mod_proxy_html的内容来重写HTML内容中的链接。