Forum Discussion

adam21983_1462's avatar
adam21983_1462
Icon for Nimbostratus rankNimbostratus
Jan 18, 2013

Simple URL Redirect Question

Hello Everyone,

 

 

Sorry if this is overly simple but I am driving myself crazy trying to get this to work. In the below iRule my redirect works if the request is sent to http://redirecttest.mysite.com but does not work if the request is sent to http://www.redirecttest.mysite.com

 

 

How can i get this to work if "www" is part of the HOST?! Thanks to everyone! -Adam

 

 

when HTTP_REQUEST {

 

if { ([string tolower [HTTP::host]] equals "redirecttest.mysite.com") } {

 

HTTP::redirect http://google.com

 

}

 

 

if { ([string tolower [HTTP::host]] equals "www.redirecttest.mysite.com") } {

 

HTTP::redirect http://google.com

 

}

 

 

6 Replies

  • Try this;

    
    when HTTP_REQUEST {
     if { (([string tolower [HTTP::host]] equals "redirecttest.mysite.com") or ([string tolower [HTTP::host]] equals "www.redirecttest.mysite.com"))} {
      HTTP::redirect "http://google.com"
      return
     }
    }
    
  • Hi Guys, Unfortunetly neither of these options are working for me. Any ideas? Thanks! -Adam
  • Hi Guys, Unfortunetly neither of these options are working for me. Any ideas? Thanks! -Adam
  • doesn't your original irule work??

    [root@ve10:Active] config  b virtual bar list
    virtual bar {
       destination 172.28.19.252:80
       ip protocol 6
       rules myrule
       profiles {
          http {}
          tcp {}
       }
    }
    [root@ve10:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
      if { ([string tolower [HTTP::host]] equals "redirecttest.mysite.com") } {
        HTTP::redirect http://google.com
      }
    
      if { ([string tolower [HTTP::host]] equals "www.redirecttest.mysite.com") } {
        HTTP::redirect http://google.com
      }
    }
    }
    
    [root@ve10:Active] config  curl -I http://redirecttest.mysite.com
    HTTP/1.0 302 Found
    Location: http://google.com
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve10:Active] config  curl -I http://www.redirecttest.mysite.com
    HTTP/1.0 302 Found
    Location: http://google.com
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    
  • Jnon's avatar
    Jnon
    Icon for Nimbostratus rankNimbostratus
    As mentioned above - it should work if you eliminate the www and change to contains as follows

     

     

    when HTTP_REQUEST {

     

     

    if { ([string tolower [HTTP::host]] contains "redirecttest.mysite.com") } {

     

    HTTP::redirect http://google.com

     

    }