For more information regarding the security incident at F5, the actions we are taking to address it, and our ongoing efforts to protect our customers, click here.

Forum Discussion

Joseph_Johnson_'s avatar
Joseph_Johnson_
Icon for Nimbostratus rankNimbostratus
Jul 14, 2014

HTTP Redirect to Different Domain

Hi,

 

I am fairly new to F5 irules and i have been tasked with setting up a redirect from a marketing url to the login of an already established site within our company. I am using a simple url redirect:

 

when HTTP_REQUEST { HTTP::respond 301 "Location" "http://sub.domain.com[HTTP::uri]OLA/faces/login.jspx?" }

 

The problem is we have two sites already point to the virtual server that uses an irule to redirect the url for sub.domain.com and domain2.com to https and adding the uri that i have above. Is there a way that to have a statment something like

 

If the request equals www.sub.com redirect to "http://sub.domain.com[HTTP::uri]OLA/faces/login.jspx?" else take the host which would be sub.domain.com or domain2.com and add the uri at the end?

 

Thanks

 

2 Replies

  • Something like this perhaps:

    when HTTP_REQUEST {
        switch -glob [string tolower [HTTP::host]] {
            "www.sub.com" {
                HTTP::respond 301 Location "http://sub.domain.com[HTTP::uri]OLA/faces/login.jspx?"
            }
            "sub.domain.com" -
            "domain2.com" {
                HTTP::respond 301 Location "https://sub.domain.com[HTTP::uri]OLA/faces/login.jspx?"
            }
        }
    }
    
  • What URLs on those hosts do you want to send to a login page? Do you want to tie that to the presence of a session of a cookie? Might end up with some redirect loops otherwise. The basic structure you are looking for:

    when HTTP_REQUEST {
      switch [HTTP::host] {
        "www.sub.com" {
          if { [string tolower [HTTP::uri]] eq "" } {
            HTTP::respond 301 Location "http://sub.domain.com/OLA/faces/login.jspx?"
          }
        }
        "sub.domain.com" -
        "domain2.com" {
          if { [string tolower [HTTP::uri]] eq "" } {
            HTTP::respond 301 Location "http://[HTTP::host]/OLA/faces/login.jspx?"
          }
        }
        default { reject }
      }
    }