Forum Discussion

Jeff_Eskens_428's avatar
Jeff_Eskens_428
Icon for Nimbostratus rankNimbostratus
Apr 30, 2015

trying to redirect a url

I am trying to redirect a URL from site.domain.com to site.domain.com/subsite. I have the F5 configured for SSL off-loading so anything that come in is redirected from http to https. When a user goes to https://site.domain.com I want them to be redirected to https://site.domain.com/newsite. I tried different iRules but none of them seem to work. Has anyone done this before?

 

11 Replies

  • Edited to include loop break/fix

    Hello Jeff,

    On VIP-80 you'll have the http -> https redirect. On VIP-443 you could use the one below. What issues are you running into?

    RULE-x.x.x.x-443
    when HTTP_REQUEST {
       if { [string tolower [HTTP::host]] equals "site.domain.com" and !([HTTP::uri] starts_with "/subsite") } {
          set respond value to 301 or 302 as preferred
          HTTP::respond 302 Location "https://site.domain.com/subsite"
    }
    }
    
    • DEJ_159363's avatar
      DEJ_159363
      Icon for Cirrus rankCirrus
      One clarification. You are doing SSL off-loading by applying a client ssl profile on the 443 VIP, correct?
    • nitass's avatar
      nitass
      Icon for Employee rankEmployee
      i think you also have to include (check) uri or path in the if-condition. otherwise, it is going to be loop because it redirects to the same fqdn.
    • DEJ_159363's avatar
      DEJ_159363
      Icon for Cirrus rankCirrus
      Thank you for catching that N. Would the below break the redirect loop appropriately? when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "site.domain.com" and !([HTTP::uri] starts_with "/subsite")} { set respond value to 301 or 302 as preferred HTTP::respond 302 Location "https://site.domain.com/subsite" } }
  • DEJ's avatar
    DEJ
    Icon for Nimbostratus rankNimbostratus

    Edited to include loop break/fix

    Hello Jeff,

    On VIP-80 you'll have the http -> https redirect. On VIP-443 you could use the one below. What issues are you running into?

    RULE-x.x.x.x-443
    when HTTP_REQUEST {
       if { [string tolower [HTTP::host]] equals "site.domain.com" and !([HTTP::uri] starts_with "/subsite") } {
          set respond value to 301 or 302 as preferred
          HTTP::respond 302 Location "https://site.domain.com/subsite"
    }
    }
    
    • DEJ's avatar
      DEJ
      Icon for Nimbostratus rankNimbostratus
      One clarification. You are doing SSL off-loading by applying a client ssl profile on the 443 VIP, correct?
    • nitass's avatar
      nitass
      Icon for Employee rankEmployee
      i think you also have to include (check) uri or path in the if-condition. otherwise, it is going to be loop because it redirects to the same fqdn.
    • DEJ's avatar
      DEJ
      Icon for Nimbostratus rankNimbostratus
      Thank you for catching that N. Would the below break the redirect loop appropriately? when HTTP_REQUEST { if { [string tolower [HTTP::host]] equals "site.domain.com" and !([HTTP::uri] starts_with "/subsite")} { set respond value to 301 or 302 as preferred HTTP::respond 302 Location "https://site.domain.com/subsite" } }
  • Sekhar's avatar
    Sekhar
    Icon for Nimbostratus rankNimbostratus

    Hi Jeff, I think you are trying to redirect based on a uri

    when HTTP_REQUEST {
      if { [HTTP::uri] == "/" } {
      HTTP::redirect "https://[HTTP::host]/newsite" 
      }
    }
    

    Thanks, Sekhar