Forum Discussion

bwilliam's avatar
bwilliam
Icon for Cirrus rankCirrus
Sep 24, 2018

iRule Assistance with redirecting multiple URLs to a single URL using an existing Redirect iRule

I currently have a universal redirect and have a requirement to add the below to this irule. Since I am unfamiliar with irules I am hoping a DevCentral community expert can assist.

I need to redirect these urls http://sitename.com, https://sitename.com, http://www.sitename.com & https://www.sitename.com

To this url https://www.sitename.io

Our current irule looks like this with several entries inside the beginning HTTP_REQUEST.

when HTTP_REQUEST {
switch -glob [string tolower [HTTP::host]] {   
  "*www.sitename.net*" {
     HTTP::redirect "https://sitename.sitename.com"
  }
  default {
      add the default action you prefer ie "www.def.com"
     HTTP::redirect "https://[HTTP::host][HTTP::uri]"
    }
  }
}    
  • Assuming you want to keep , the following additional entry should cover the four examples you listed:

    when HTTP_REQUEST {
       switch -glob [string tolower [HTTP::host]] {   
          "*www.sitename.net*" {
             HTTP::redirect "https://sitename.sitename.com"
          }
          "*sitename.com" {
             HTTP::redirect "https://www.sitename.io"
          }
          default {
              add the default action you prefer ie "www.def.com"
             HTTP::redirect "https://[HTTP::host][HTTP::uri]"
          }
       }
    }
    
  • Thank you. A simple wildcard does the trick, go figure. I guess that makes sense given the sitename.com is static and we only want to trigger the redirect if any of the variables preceding sitename.com changes.