Forum Discussion

DChu_344155's avatar
DChu_344155
Icon for Nimbostratus rankNimbostratus
Dec 15, 2017

HTTP Redirect not working

I am new to iRules and I am trying to setup an iRule to redirect some traffic. I want to do this when status 301 and 302 are returned in the headers, but for basic testing I went with just the below iRule. I can't seem to get the redirect to work let alone try to incorporate the 301 and 302. Any advice is greatly appreciated

 

when HTTP_REQUEST { if {([HTTP::host] equals ";) } { HTTP::redirect "; } }

 

  • You will need an iRule something like this:

     

    when HTTP_REQUEST {

     

    if {([HTTP::host] equals ";) } {

     

    HTTP::redirect "; [HTTP::uri]

     

    }

     

    }

     

  • when you request URL http://www.domain123.com/.well-known/acme-challenge/aeIswOdWkV3TlYv24PI7Nv9OYvcF0eKfyrLlVpdSW7s, the HTTP request is:

    GET /.well-known/acme-challenge/aeIswOdWkV3TlYv24PI7Nv9OYvcF0eKfyrLlVpdSW7s HTTP/1.1
    Host: www.domain123.com
    User-Agent: Mozilla/4.0......
    

    So following HTTP commands return:

    • HTTP::host -->
    • HTTP::uri --> /.well-known/acme-challenge/aeIswOdWkV3TlYv24PI7Nv9OYvcF0eKfyrLlVpdSW7s

    So the irule must be:

    when HTTP_REQUEST { 
        if {([HTTP::host] equals "www.domain123.com") } { 
            HTTP::redirect "http://www.somethingelse.com[HTTP::uri]"
        } 
    }
    

    or if you want to manage URI in condition:

        when HTTP_REQUEST { 
        if {([HTTP::host] equals "www.domain123.com") && [HTTP::uri] starts_with "/.well-known/acme-challenge/"} { 
            HTTP::redirect "http://www.somethingelse.com[HTTP::uri]"
        } 
    }