Forum Discussion

barry_8239's avatar
barry_8239
Icon for Nimbostratus rankNimbostratus
Nov 30, 2012

irule http redirect help

Hi All, i am fairly new to F5 world and need some assistance in redirecting a url. I've tried the following, but the browser will still show http://example/test and not the new url http://newserver/test. Any helpo is much appreciated.

 

when HTTP_REQUEST {

 

if{ [HTTP::host] contains "example/test"} {

 

HTTP::redirect http://newserver/test[HTTP::uri]

 

}

 

}

 

9 Replies

  • Try this;

    
    when HTTP_REQUEST {
        if { [HTTP::host] contains "example/test" } {
          HTTP::redirect "http://newserver/test[HTTP::uri]"
        }
    }
    
  • I'm not sure why you're adding the old URI to the new, this might work better;

     
     when HTTP_REQUEST { 
         if { [HTTP::host] contains "example" } { 
           HTTP::redirect "http://newserver[HTTP::uri]" 
         } 
     }
  • I'm not sure why you're adding the old URI to the new, this might work better;

    
    when HTTP_REQUEST {
        if { [HTTP::host] contains "example" } {
          HTTP::redirect "http://newserver[HTTP::uri]"
        }
    }
    
  • You are the best!! That was it! Thank you very much. Redirect works like a charm.

     

     

    Thanks again

     

  • I have it halfway working now. IS there a way to add another host name to the above irule?

     

     

    The redirect works when entering example in the browser, but i also need to add "sample" as well. Would the following work? When i put sample in the url i get an iis page and not redirected to newserver.

     

     

    when HTTP_REQUEST {

     

    if { [HTTP::host] contains "example" or "sample" } {

     

    HTTP::redirect "http://newserver[HTTP::uri]"

     

    }

     

    }

     

     

    when HTTP_REQUEST {

     

    if { [HTTP::host] contains "example" or "sample" } {

     

    HTTP::redirect "http://newserver[HTTP::uri]"

     

    }

     

    }
  • Sure, try this;

    
    when HTTP_REQUEST {
      switch -glob [string tolower [HTTP::host]] {
        "example*" -
        "sample" {
          HTTP::redirect "https://otherserver.com[HTTP::uri]"
        }
    }
    
  • i get all sort of parameter errors when i do an update after adding the rule
  • This is what i tried to add

     

     

    when HTTP_REQUEST {

     

    switch -glob [string tolower [HTTP::host]] {

     

    "example*" -

     

    "sample" {

     

    HTTP::redirect "http://newserver[HTTP::uri]"

     

    }

     

    }
  • Sorry, missing the last bracket;

    
    when HTTP_REQUEST {
      switch -glob [string tolower [HTTP::host]] {
        "example*" -
        "sample" {
          HTTP::redirect "https://otherserver.com[HTTP::uri]"
        }
     }
    }