Forum Discussion

gcaba_31903's avatar
gcaba_31903
Icon for Nimbostratus rankNimbostratus
Dec 08, 2011

simple irule that does host redirect with wildcard

hi,

 

 

i'm in the process of retiring a domain and all websites behind it, so I need to redirect all of them to a new domain.

 

 

- so far I got this rule working, see code below,

 

 

when HTTP_REQUEST {

 

if {[HTTP::host] contains www.abc.com}

 

{HTTP::redirect "HTTP://www.cde.com[HTTP::uri]"}

 

elseif {[HTTP::host] equals "abc.com"}

 

{HTTP::redirect }

 

}

 

 

but given the amount of sites I would like to make more general and use a wild card

 

 

 

when HTTP_REQUEST {

 

if {[HTTP::host] contains *.abc.com}

 

{HTTP::redirect }

 

}

 

 

 

thanks,

 

 

 

 

but given the amount of sites I would like to make more general and use a wild card

 

 

 

 

 

 

 

 

 

3 Replies

  • can you try this?

    [root@ve1023:Active] config  b virtual bar list
    virtual bar {
       snat automap
       pool foo
       destination 172.28.19.79:80
       ip protocol 6
       rules myrule
       profiles {
          http {}
          tcp {}
       }
    }
    [root@ve1023:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
            if {[string tolower [HTTP::host]] ends_with "abc.com"} {
                    HTTP::redirect "http://www.cde.com[HTTP::uri]"
            }
    }
    }
    
    [root@ve1023:Active] config  curl -I http://abc.com
    HTTP/1.0 302 Found
    Location: http://www.cde.com/
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve1023:Active] config  curl -I http://www.abc.com
    HTTP/1.0 302 Found
    Location: http://www.cde.com/
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
    [root@ve1023:Active] config  curl -I http://whatever.abc.com
    HTTP/1.0 302 Found
    Location: http://www.cde.com/
    Server: BigIP
    Connection: Keep-Alive
    Content-Length: 0
    
  • nitass,

     

     

    thanks for your reply. i'll give it a try and let you know how it went.

     

     

  • nitass,

     

     

    thanks for your reply. i'll give it a try and let you know how it went.