Quantcast
Viewing all articles
Browse latest Browse all 1529

Using UrlRewriteFilter to get Tomcat to return a 301 redirect from http to https

I'm trying to find out if anyone has succeeded in using the UrlRewriteFilteravailabe from http://tuckey.org/urlrewrite/ to do a 301 permanent redirect fromhttp to https in Apache Tomcat but I don't seem to be getting anywhere fast. A number of people have asked the same question and AFAICS none have been answeredIf I'm asking in the wrong place then maybe someone would be kind enough to 'redirect' me to the right place.If it's not possible then perhaps someone could say so.

Thank you.

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

The 'standard' configuration as recommended by the 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" />

entering localhost in a browser results in redirection to httpschecking this with curl we can see that this works as expected but we get 302 temporary redirect

    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

However this is unnacceptable to Google who prefer a 301 permanent

Is it possible to use UrlRewriteFilter to achieve this end

The following rule results in a 302 even though I'm using to type="permanent-redirect"everything else stays the same

<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>

I have tried various different combinations with no luck presumably because Tomcat is redirecting after the filter has been applied

Has anyone actually got this to work so that we get a 301 instead of a 302

Thank You


Viewing all articles
Browse latest Browse all 1529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>