As far as I can tell, this is not easy to do with any of the rules/handlers that are shipped with Jetty 6.
The RedirectPatternRule
matches on the target
which is the path in the Jetty server, and not the full URI, so your rule is never matching.
You could change it to:
<New id="redirect" class="org.mortbay.jetty.handler.rewrite.RedirectPatternRule">
<Set name="pattern">/*</Set>
<Set name="location">https://foobar.com</Set>
</New>
However, that has 2 issues:
- It will redirect all requests (even
https
requests)
- It doesn't take the requested URL into account (it always redirects to
location
as it is specified, and ignores anything that was matched by the pattern
)
You can overcome the first issue with some trickery.
You can wrap the RewriteHandler
in a ContextHandler
, and a context handler allows you to specify which connectors it will handle requests from (setConnectorNames
). So, you could use that to make the rewrite only apply to requests on the http connector(s).
I can't think of a way to overcome the second issue though.
I think your best bet will to write your own redirect rule for this. If you don't have development resources to do that for you, then contact me (you can find my email address via my blog, which is in my profile) and I can whip one up (under the same license as Jetty). It will be pretty straight forward to write a rule that simply redirects http to https.