Forum Discussion

RobW's avatar
RobW
Icon for Nimbostratus rankNimbostratus
Mar 25, 2008

302 redirect

High my name is Rob and I'm iRule challenged. I'm running v9.4.4 and I have a 443 virtual server with client side SSL processing. I need to handled 302 status codes differently depending on the returned server port.

 

The conditions are as follows:

 

302 port 81 process through https - Currently working using either iRule listed below.

 

302 port 443 process through https - Currently working using either iRule listed below.

 

302 port 80 process/redirect via http - Currently not working using either iRule listed below.

 

 

HTTP Watch out - 302 redirect port 80

 

00:00:00.000HTTP 404 Not Found

 

+ 0.0000.0451491348GET302Redirect to https://www.testurl.com/ports/index.htmlhttps://www.allnewstest.com/suitetest/portal/linkhandler.do?url=http%3A//www.testurl.com/ports/index.html

 

+ 0.0470.300297588GET404text/htmlhttps://www.testurl.com/ports/index.html

 

0.34717889362 requests

 

 

 

when HTTP_RESPONSE {

 

if {([HTTP::status] starts_with "3") and ([TCP::server_port] equals "81")} {

 

HTTP::header replace Location [string map {http: https:} [HTTP::header value Location]]

 

}

 

elseif {([HTTP::status] starts_with "3") and ([TCP::server_port] equals "80")} {

 

SSL::disable}

 

}

 

 

 

when HTTP_RESPONSE {

 

if {([HTTP::status] starts_with "3") and ([TCP::server_port] equals "81")} {

 

HTTP::header replace Location [string map {http: https:} [HTTP::header value Location]]

 

}

 

elseif {([HTTP::status] starts_with "3") and ([TCP::server_port] equals "443")} {

 

HTTP::header replace Location [string map {https: https:} [HTTP::header value Location]]

 

}

 

elseif {([HTTP::status] starts_with "3") and ([TCP::server_port] equals "80")} {

 

HTTP::header replace Location [string map {http: http:} [HTTP::header value Location]]

 

}

 

}

 

 

 

Thanks,

 

Rob

5 Replies

  • RobW's avatar
    RobW
    Icon for Nimbostratus rankNimbostratus
    Hello,

     

    When I change my iRule to the following, I receive a error in the iRule editor.

     

     

    when HTTP_RESPONSE {

     

    if {([HTTP::status] starts_with "3") and ([TCP::server_port] equals "81")} {

     

    HTTP::header replace Location [string map {http: https:} [HTTP::header value Location]]

     

    }

     

    elseif {([HTTP::status] starts_with "3") and ([HTTP::collect] contains "url=http")} {

     

    HTTP::redirect "http://[HTTP::host][HTTP::uri]"}

     

    }

     

     

    Thanks,

     

    Rob
  • [HTTP::uri] is not a valid command under under HTTP_RESPONSE event.

     

     

    /cb

     

  • RobW's avatar
    RobW
    Icon for Nimbostratus rankNimbostratus
    when HTTP_RESPONSE {

     

    if {([HTTP::status] starts_with "3") and ([TCP::server_port] equals "81")} {

     

    HTTP::header replace Location [string map {http: https:} [HTTP::header value Location]]

     

    }

     

    elseif {([HTTP::status] starts_with "3") and ([HTTP::collect] contains "url=http")} {

     

    HTTP::redirect "http://[HTTP::host][HTTP::uri]"}

     

    }

     

     

    The error is apparently in the "HTTP::redirect" statement. withing the portal users have the ability to click on useful links. These links are both HTTPS and HTTP 302 redirection. The HTTPS links work fine, but the HTTP links are served back to the the client via HTTPS. I need to have the HTTP links served back to the client via HTTP.

     

     

    -Rob
  • You might want to try to the URI with the HTTP_REQUEST event and then pass that into a variable which can be used within the redirect.

     

     

    my 2 cents

     

    /cb
  • RobW's avatar
    RobW
    Icon for Nimbostratus rankNimbostratus
    In my case I have an issuse with the way the http profile rewrite matching statement is handling http 302 directs from the servers. So, I have to intercept the GETs for HTTP sites and let the LTM redirect the user.

     

     

    when HTTP_REQUEST {

     

     

    if { [HTTP::uri] contains "linkhandler.do?url=http%3A" } {

     

     

    set dest_url [URI::decode [lindex [ split [HTTP::uri] "="] 1]]

     

    HTTP::redirect $dest_url

     

    }

     

    else {

     

    return

     

    }

     

    }