Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral


Questions and Answers

Loading... Loading...

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 Answer(s):

Instead of 'equals' use 'contains'
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

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
}

Your answer:

You must be logged in to reply. You can login here.