Forum Discussion

mohana_322852's avatar
mohana_322852
Icon for Nimbostratus rankNimbostratus
Jun 02, 2017

Need help for redirction of append URI

I have difficulties in redirection- I want to do a redirection abc.com to abc.com/act on both http and https

when HTTP_REQUEST { if {[string tolower [HTTP::host]] equals"abc.com" or [string tolower [HTTP::host]] equals"abc.com"}{

switch -glob [HTTP::path] {
    "/*" {HTTP::respond 301 Location " https://abc.com/act[HTTP::uri]"}

} }

Or

when HTTP_REQUEST { if {[string tolower [HTTP::host]] equals"abc.com"}{ if {[HTTP::uri] starts_with "/act" }{ HTTP::uri /act[HTTP::uri] log "hit uri act"} } }

Both rules are not working Kindly give an advice

Thank you

3 Replies

  • Hi,

     

    you can try this code:

     

    when HTTP_REQUEST {
        if {[string tolower [HTTP::host]] equals "abc.com" && !([HTTP::path] starts_with "/act" )}{
            HTTP::respond 301 Location "/act[HTTP::uri]"
            log local0. "[HTTP::uri] redirected to /act[HTTP::uri]"
            return
        }
    }
  • when HTTP_REQUEST { if {[string tolower [HTTP::host]] equals"abc.com" or [string tolower [HTTP::host]] equals"abc.com"}{

    switch -glob [HTTP::path] { "/" {HTTP::respond 301 Location " https://abc.com/act[HTTP::uri]"}

    I would like to withdraw my request. It is working with above iRule.
    
    Thank you
    
  • Why do you compare twice HTTP::host with abc.com?

    The irule may not work without space between

    equals
    and
    "abc.com"

    Do you only want to redirect / or all URI not starting with /act ?

    If redirection is on the same service than the first request (user request https://abc.com/ and you want to redirect to https://abc.com/act/), you can redirect to relative URI instead of absolute:

    HTTP::respond 301 Location "/act[HTTP::uri]"
    

    a switch command in this irule is useless and a if may be used...