Forum Discussion

f5now_28704's avatar
f5now_28704
Icon for Nimbostratus rankNimbostratus
Aug 29, 2007

301 redirects

Hi Guys.

 

 

I have a question, with my iRule set, I have about 40 domains going to one Virtual Server(192.168.1.200).

 

 

Now Marketing wants to redirect 301, 10 domains of the 40.

 

 

here is my irule for simple 301 redirection, this works but(trying to avoid changing all the DNS records) is there a way to setup this rule just to answer for 10 of the domains and pass the other 30 to where ever they needed to go?

 

 

 

-----------------------

 

when HTTP_REQUEST {

 

HTTP::respond 301 Location "http://[getfield www.abc.com ":" 1][HTTP::uri]"

 

}

 

-----------------------

 

 

Thanks for the Help

 

Ryan

2 Replies

  • Sure thing. You can either put all the domains you want redirected into a class (Data Group). Look at the wiki for matchclass and you'll see an example. Or, you could hard code it in your iRule with a switch statement

     

     

    when HTTP_REQUEST {
      switch [HTTP::host] {
        www.domain1.com -
        www.domain2.com - 
        www.domain3.com -
        www.domain4.com -
        www.domain5.com -
        www.domain6.com -
        www.domain7.com -
        www.domain8.com -
        www.domain9.com -
        www.domain10.com {
          HTTP::respond 301 Location "http://www.abc.com[HTTP::uri]" 
        }
      }
    }

     

     

    I've removed your "getfield" command as it will always return "www.abc.com" since there is no ":" in that string. You want to use the getfield command in this situation when you are working drectly on the HTTP::host where the client enters something like this:

     

     

    http://www.foo.com:80/dir1

     

     

    In this case HTTP::host will be "www.foo.com:80" and you'll need to do the getfield to extract "www.foo.com".

     

     

    -Joe