Tomcat HTTP to HTTPS redirect

Option 1

  1. Update web.xml configuration file and add the following content into the <web-app> section:

    <security-constraint> <web-resource-collection> <web-resource-name>Protected Context</web-resource-name> <url-pattern>/*</url-pattern> </web-resource-collection> <!-- auth-constraint goes here if you require authentication --> <user-data-constraint> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint> </security-constraint>

    Screenshot__2_.png
  1. Update server.xml configuration file and add the following content into the <Host> section:

    <Valve className="org.apache.catalina.valves.RemoteIpValve" remoteIpHeader="x-forwarded-for" protocolHeader="x-forwarded-proto" protocolHeaderHttpsValue="https" />

    Screenshot__3_.png

Option 2

  1. Make sure you have lib directory under WEB-INF
    Upload the file urlrewritefilter-4.0.3.jar there. You can find the latest version at this page
  2. Update web.xml configuration file and add the following content into the <web-app> section:

    <filter> <filter-name>UrlRewriteFilter</filter-name> <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class> </filter> <filter-mapping> <filter-name>UrlRewriteFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
  3. Create a file WEB-INF/urlrewrite.xml with the following contatnt:

    <?xml version="1.0" encoding="utf-8"?> <!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 4.0//EN" "http://www.tuckey.org/res/dtds/urlrewrite4.0.dtd"> <urlrewrite> <rule> <name>Redirect to HTTPS</name> <condition operator="notequal" name="x-forwarded-proto">https</condition> <from>^.*$</from> <to last="true" type="permanent-redirect">https://%{server-name}%{request-uri}</to> </rule> </urlrewrite>

    Finally, restart the Tomcat.
     
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Secure Java Encryption and Decryption

Secure Java Encryption and Decryption in CloudJiffy Java security technology includes a...

Timezone Data for Java/PHP App Server

  Managing Timezone Data for Java/PHP App Server All of the Java and PHP application servers...

Spring Boot Standalone and Clustered Java Applications with CloudJiffy

Spring Boot Standalone and Clustered Java Applications with Cloudjiffy Since the very...

Environment Variables - Java custom Environment Variables

Environment variables represent a kind of placeholders, where you can store the frequently...

Java App server Configuration

To perform the necessary configurations, press the Config button next to your application...

Powered by WHMCompleteSolution