Using UrlRewriteFilter to get Tomcat to return 301 redirects from http to https

I'm trying to find out if anyone managed to use the UrlRewriteFilter availabe from http://tuckey.org/urlrewrite/ to do 301 permanent redirects from http to https to Apache Tomcat, but I don't seem to get fast. A number of people asked the same question, and AFAICS no one answered. If I ask in the wrong place, maybe someone will be kind enough to “redirect” me to the right place. If this is not possible, maybe someone can say it.

Thank.

    apache-tomcat-7.0.42
    jdk1.8.0_77
    CentOS Linux 7.2.1511
    urlrewritefilter-4.0.3.jar

The standard configuration recommended by tomcat docs is as follows

    web.xml

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>Secure URLs</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>

    server.xml

    <Connector port="80" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="443" />

    <Connector port="443" maxThreads="150" scheme="https" secure="true"
           SSLEnabled="true" keystoreFile="/opt/keys/tomcat.keystore" 
           keystorePass="*********" clientAuth="false" keyAlias="tomcat" sslProtocol="TLS" />

localhost https curl, , , , 302

    root@sandbox:/tmp# curl -D /tmp/headers.txt -s  http://localhost

    HTTP/1.1 302 Found
    Server: Apache-Coyote/1.1
    Cache-Control: private
    Expires: Thu, 01 Jan 1970 01:00:00 GMT
    Location: https://localhost/
    Content-Length: 0
    Date: Fri, 29 Apr 2016 18:24:47 GMT

Google, 301

UrlRewriteFilter ?

302, type = "Permanent-redirect"

    <rule>
       <name>seo redirect</name>
       <condition name="host" operator="notequal">^www_example_com</condition>
       <condition name="host" operator="notequal">^localhost</condition>
       <from>^/(.*)</from>
       <to type="permanent-redirect" last="true">https://www_example_com/$1</to>
    </rule>

, , Tomcat

- , 301 302

+4

All Articles