Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We have Tomcat 5.5 running behind and Apache 2.2 mod_proxy. We would like prettier URLs. For example, this is more or less how our URLs look now:

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)

We would like the publically exposed URLs to be simpler, e.g.:

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)

I know how to have Apache rewrite the incoming URLs into the longer ones Tomcat uses, but I'm concerned that this might confuse Tomcat. I am reasonably experienced with Apache but a Tomcat newbie.

Also, we want to do this with rewriting, not redirects (e.g., http://example.com/ should not simply redirect to http://example.com/foo/app/home), as we want to keep the ugly URLs out of the address bar entirely.

share|improve this question
    
This sounds like a request from a pointy haired boss. "What can we do to make the URL's prettier?" Also, this one goes to eleven and can be none more black. –  joeqwerty Nov 24 '10 at 18:10
    
@joe, simple URLs improve the usability of a site –  Reid Nov 24 '10 at 18:58
    
How so? I understand that they make the address bar look nicer, but how do they increase or enhance the usability of a site? Giving my car a new paint job doesn't make it run any better. –  joeqwerty Nov 24 '10 at 19:07
    
add comment

1 Answer 1

If you're rewriting everything to a common location, you would typically do something like this:

ProxyPass        / http://localhost:8080/foo/
ProxyPassReverse / http://localhost:8080/foo/

If you need different rules for different paths, you would probably use the Proxy flag on a series of RewriteRules:

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]

The this will send things to the appropriate place in Tomcat.

The only complication is if the application dynamically generates URLs with fully qualified paths. In this case, you need to either fix the application, or use something like mod_proxy_html to rewrite links in your HTML content.

share|improve this answer
    
+1 Given proper rewrite rules Tomcat will never know what the original URLs were but only see the rewritten ones. Did this quite often with good success and mod_rewrite is the proper tool. –  Axel Knauf Jul 16 '11 at 13:42
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.