URLRewriteFilter HTTP to HTTPS rule returning net:

2020-07-27 05:20发布

问题:

I have Tomcat running with URLRewriteFilter behind an EC2 ELB with SSL certs,the ELB is redirecting traffic from ports 80 and 443 to port 8080 in the backend instances. URLRewriteFilter has this rule:

<rule>
    <condition type="scheme" operator="notequal">https</condition>
    <condition name="host" operator="equal">ELB-DNS</condition>
    <from>^/(.*)</from>
    <to type="permanent-redirect">https://ELB-DNS/$1</to>
</rule>

but when I try hitting it, I got this:

Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.

回答1:

Try setting the port condition:

<rule>
    <condition type="scheme" operator="notequal">https</condition>
    <condition name="host" operator="equal">ELB-DNS</condition>
    <condition name="port" operator="equal">(80|443)</condition>
    <from>^/(.*)</from>
    <to type="permanent-redirect">https://ELB-DNS:8080/$1</to>
</rule>