Forum Discussion

TenYr_214337's avatar
TenYr_214337
Icon for Nimbostratus rankNimbostratus
Aug 05, 2015

iRules Redirect Site to Site

Question: I have created this Redirect. Can anyone tell me why this is not working?

 

when HTTP_REQUEST { set host_lowcase [string tolower [HTTP::header "Host"]]

 

switch -glob $host_lowcase { "\MySite.Mynet.com" { HTTP::redirect https://MyNew.Mynet.com[HTTP::uri] } } }

 

2 Replies

  • Sorry but this iRule has too many problems to bring out anything in particular. Please modify the iRule below to meet the requirements of your environment.

    HTTP_REQUEST {
    
      switch [HTTP::host] {
        "mysite.mynet.com" {
          HTTP::respond 302 location "https://mynew.mynet.com[HTTP::uri]"
        }
        "mysite2.mynet.com" {
          HTTP::respond 302 location "https://mynew2.mynet.com[HTTP::uri]"
        } default {
          return 
           apply no redirect
        }
      }
    
    }
    
  • Hi, little change of the irule with:

    • it's better to convert HTTP:host to lowercase before string evaluation

    .

    HTTP_REQUEST {
    
      switch [string tolower [HTTP::host]] {
        "mysite.mynet.com" {
          HTTP::respond 302 location "https://mynew.mynet.com[HTTP::uri]"
        }
        "mysite2.mynet.com" {
          HTTP::respond 302 location "https://mynew2.mynet.com[HTTP::uri]"
        } default {
          return 
           apply no redirect
        }
      }
    
    }
    

    What was wrong in the first iRule:

    • if you evaluate a lowercase string with uppercase string... it will never match 🙂
    • the hostname never start with "\"