Forum Discussion

amul_191720's avatar
amul_191720
Icon for Nimbostratus rankNimbostratus
Mar 11, 2015

HTTPS to HTTP redirection is not happening with irule

Hi ,

 

Could you please help here in this redirection irule. I tried all the way but i am not able to redirect this https traffic.

 

when HTTP_REQUEST { if { [HTTP::uri] starts_with "/xyz.com" }{ HTTP::redirect "http://zyx.com"

 

} elseif { [HTTP::uri] starts_with "/www.xyz.com" }{ HTTP::redirect "http://zyx.com" } }

 

=====

 

when HTTP_REQUEST { if {[HTTP::uri] equals {https://xyz.com}} {HTTP::uri {https://zyx.com} } }

 

Thanks and Regards, Amul

 

4 Replies

  • Hi Amul, you want to test for the host-header to get it working:

    when HTTP_REQUEST { 
        if {[string tolower [HTTP::host]] equals "xyz.com"} { 
            HTTP::redirect "http://zyx.com"
        } elseif {[string tolower [HTTP::host]] equals "www.xyz.com"} {
            HTTP::redirect "http://zyx.com"
        } 
    }
    

    Second iRule:

    when HTTP_REQUEST {
        if {[string tolower [HTTP::host]] equals "xyz.com"} {
            HTTP::redirect http://zyx.com/
        }
    }
    

    Thanks, Stephan

    Edited: Add 2nd iRule upon specification
  • Hi Stephen,

     

    Thanks for your reponse. But the real situation here..

     

    I need to redirect the https traffic to http ..

     

    The scenario is :

     

    We had URL but this is decommissioned http URL ( with new functionality...

     

    The request here is .. I have created Virtual server with server port 443, I have mapped the irule to redirect https traffic to http.

     

    when HTTP_REQUEST { if {[HTTP::uri] equals {https://xyz.com}} {HTTP::uri {http://zyx.com} } }

     

    Could you please help me with your solution to resolve this issue.

     

    • StephanManthey's avatar
      StephanManthey
      Icon for MVP rankMVP
      Hi Amul, I just added the modified second iRule above. You will bind it to the virtual server and in case of matching hostname it will redirect to http. If you want to use the same virtual server for the old and new hostname you need to use SAN certificates or add multiple client-ssl profiles (requires client support for Server Name Indication [SNI]). If a client enters a URL like this: http://xyz.com/abcpath?defquery=param, the HTTP commands return the following: [HTTP::host] > xyz.com [HTTP::path] > /abcpath [HTTP::query] > defquery=param [HTTP::uri] > /abcpath?defquery=param That´s why your version of iRules did not work as you expected. Thanks, Stephan
  • Amul,

    Why not just use the same as the built in iRule to go from HTTP to HTTPS... just change the https to http and apply this to the 443 virtual.

    when HTTP_REQUEST {
       HTTP::redirect http://[getfield [HTTP::host] ":" 1][HTTP::uri]
    }
    

    Seth