3

I want make permanent redirect from http:// myurl to https:// myurl, but in Jetty I find only MovedContextHandler, with it I can redirect only context path, for examnple from myurl/bla to myurl/bla/bla

<Configure class="org.mortbay.jetty.handler.MovedContextHandler">
  <Set name="contextPath">/bla</Set>
  <Set name="newContextURL">/bla/bla</Set>
  <Set name="permanent">true</Set>
  <Set name="discardPathInfo">false</Set>
  <Set name="discardQuery">false</Set>
</Configure>

but how can I work with prefix of url?

bearhunterUA
  • 259
  • 5
  • 15
  • Duplicate [of this](http://serverfault.com/questions/367660/how-to-have-jetty-redirect-http-to-https) – Oli Dec 16 '13 at 13:15

1 Answers1

6

Best handled in your /WEB-INF/web.xml

<web-app>
  ...
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>Everything in the webapp</web-resource-name>
      <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
      <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
  </security-constraint>
</web-app>
Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
  • @joakim-erdfelt Is the use of a SecureRequestCustomizer recommended when Jetty sees a 403 !SECURE error? See http://serverfault.com/a/575126 I currently have only static content. – gouessej Dec 20 '16 at 09:43
  • @gouessej SecureRequestCustomizer is needed to trigger the "is secure" check on Jetty 9+ if you intend to redirect from a Jetty terminated SSL/TLS (https) to (http). But more importantly is the requirement for a properly configured HttpConfiguration (as the redirect uses that information to perform the redirect) on your SSL/TLS (https) ServerConnectors – Joakim Erdfelt Dec 20 '16 at 13:11
  • How to do it programmatically for a specific context handler? – Pawan Singh Dec 26 '20 at 07:26