Forum Discussion

together_183451's avatar
together_183451
Icon for Nimbostratus rankNimbostratus
Apr 21, 2015

URL Redirection from Https to Http

I have to Two applications in One server, named as osabc.com and abc.com. What redirection I need is: 1) If request comes from http://abc.com then it should redirect to https://abc.com 2) If request comes from http://osabc.com then it should redirect to http://abc.com (and not on

 

I tried with IRule

 

... when HTTP_REQUEST { if { [HTTP::host] equals "osabc.com" } { HTTP::redirect "http://abc.com" } else { HTTP::redirect "https://abc.com" } } ...

 

5 Replies

  • I'm assuming the "if request comes from" actually means the client is requesting the Host specified? Depending on how your DNS resolves and how you've configured your Virtual Server TCP listeners, the iRule below should do the job.

    when HTTP_REQUEST {
    
      if { [HTTP::host] == "abc.com" }{
        HTTP::respond 302 location "https://abc.com"
        event disable
        TCP::close
      } elseif { [HTTP::host] == "osabc.com" }{
        HTTP::respond 302 location "http://abc.com"
        event disable
        TCP::close
      } else {
        Do nothing; the request will be routed to a back-end server as defined in default pool applied to a VS.
      }
    }
    
    • Hannes_Rapp's avatar
      Hannes_Rapp
      Icon for Nimbostratus rankNimbostratus
      It's a comment to illustrate what happens if the conditional actions above it are not processed. The whole "else" statement-block is optional and can be removed. Regards,
  • Hello Hannes, we have configured system default http to https irule on VIP-80 and then redirection from http to https is working perfectly. But we want to redirect some uri like abc.com/product, abc.com/ers that should not redirected towards https that should open via only http://abc.com/product instead of https://abc.com/product can you please help me for the same..

     

  • when HTTP_REQUEST {
    
      switch -glob [HTTP::host][string tolower[HTTP::path]] {
        "abc.com/product*" -
        "abc.com/product2*" -
        "abc.com/ers*" {
          HTTP paths of abc.com as defined above are not redirected to HTTPS
          return
         }
        "abc.com*" {
          All other HTTP paths of abc.com are redirected to HTTPS
          HTTP::respond 302 location "https://abc.com"
          event disable
          TCP::close
        }
        "osabc.com*" {
          All HTTP paths of osabc.com are redirected to abc.com
          HTTP::respond 302 location "http://abc.com"
          event disable
          TCP::close
        }
      }
    }
    

    Notes: you may remove the asterisks at the end of your exclusional HTTP paths (product, productX, ers) for an exact match.