How to configure Tomcat to always require HTTPS
First, make sure that you have configured and enabled both the HTTP and HTTPS
elements in your
<Connector port="8080" protocol="HTTP/1.1"
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
For details on how to prepare your conf/keystore file, see http://tomcat.apache.org/tomcat-6.0-doc/ssl-howto.html
Restart Tomcat and test both of these connectors, making sure that you can access your web application via either connector before you proceed. Next, edit your webapp's
WEB-INF/web.xml file and add the following inside of your
<!-- Require HTTPS for everything except /img (favicon) and /css. -->
This configuration declares that the entire webapp is meant to be HTTPS only, and the container should intercept HTTP requests for it and redirect those to the equivalent "https://" URL. The exception is certain requests having URL patterns that match the "HTTPSOrHTTP" web resource collection, in which case the requests will be served through the protocol the request came in on, either HTTP or HTTPS.
Lastly, restart your webapp (or Tomcat). It should now redirect HTTP requests to HTTPS, and it should serve the webapp via HTTPS only.
Do you have a question on installing, configuring, or deploying Apache Tomcat? Submit it here.