301 Redirect for SSL Deployment on Java Hosting

Published: 2018-01-16

1. Download UrlRewriteFilter and upload it to the WEB-INF/lib directory

http://downinfo.myhostadmin.net/urlrewritefilter-4.0.3.jar 


2. Modify WEB-INF/web.xml

Edit WEB-INF/web.xml and add the following before other servlet mappings


<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>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>FORWARD</dispatcher>
</filter-mapping>


3. Create a new urlrewrite.xml file under WEB-INF, and add a redirect rule [replace abc.com with your own domain]


<urlrewrite>
  <rule>
      <name>https redirect</name>
      <condition name="From-Https" operator="notequal">^on</condition>
      <from>^/(.*)</from>
      <to type="permanent-redirect" last="true">https://www.abc.com/$1</to>
  </rule>
</urlrewrite>


Note: This information comes from the Internet. If it no longer works, please contact the program provider to consult on how to handle it