Forum Discussion

Cliff_Airhart_1's avatar
Cliff_Airhart_1
Icon for Nimbostratus rankNimbostratus
Apr 07, 2005

Redirecting HTTP to a website using iRule

I am trying to setup an iRule that will provide the following:

 

 

When a user types the following URL ( http://www.company.com ) it will be redirected automaticall to

 

 

http://www.company.com:50000/dir

 

 

We don't want the users to type the service and extra directory path. We are running a BIGIP 540 with version 4.6.2

 

 

Any assistance would be greatly appreciated!

 

 

Thanks,

 

 

Cliff Airhart

 

Network Engineer

 

Spectrolab

 

cairhart@spectrolab.com

 

 

  • bknotwell_12713's avatar
    bknotwell_12713
    Historic F5 Account
    Do you need something more than the following:

           
         b rule myredir show     
         RULE myredir {     
            if (http_host == "www.company.com") {     
               redirect to "http://www.company.com:5000/dir"     
            }     
            else {     
               discard     
            }     
         } 
      
  • bknotwell_12713's avatar
    bknotwell_12713
    Historic F5 Account
    Sorry about the confusion, the initial command was the output of a rule show.

     
      
     b rule myredir '{if(http_host == "x.xx.xxx") { redirect to "http://x.xx.xxx:80/index.shtml" }' 
      
     b virtual 192.168.1.22:0 { use rule myredir } 
      
     

    From a box on the .1 network:

     
     bash-2.05b$ telnet 192.168.1.22 6666    it could be any port 
     Trying 192.168.1.22... 
     Connected to 192.168.1.22. 
     Escape character is '^]'. 
     GET / HTTP/1.0 
     Host:  x.xx.xxx 
     HTTP/1.0 302 Found 
     Location: http://x.xx.xxx:80/index.shtml 
     Connection: close 
      
     Connection closed by foreign host. 
     bash-2.05b$  
     

    Finally, it's important to understand that a 4.X rule allows a limited number of branches so if you intend to do a lot of comparisons, you'll want to do something different. I don't have anything specific, but I'd guess a rule and class combination* will give you what you want.

    *ask.f5.com probably has a good example of mapclass2node usage. I suspect the solutions guide does as well.

  • When I insert the below syntax into the Rule text section in the Configuration Utility I recieve an error:

     

     

    b rule myredir '{if(http_host == "x.xx.xxx") { redirect to "http://x.xx.xxx:80/index.shtml" }' b virtual 192.168.1.22:0 { use rule myredir }

     

     

    Error 331835 -- Rule string to tree failed. - syntax error at '''

     

    line 1: if (http_host == "xx.xxxx.com") { redirect to "http://xx.xxxx.com:50000/xxx" }'

     

     

    I also tried to use the syntax in the BIGPIPE command line section, I also received an error.

     

     

    I do see from your last post that the website was redirected. I must still be implementing it incorrectly. Are you sure that this will work with version 4.6.2 on BIGIP 540?

     

     

    More suggestions?

     

     

    Thank you for your patience...

     

     

    Cliff Airhart
  • bknotwell_12713's avatar
    bknotwell_12713
    Historic F5 Account
    I've included my shell interaction below:

     
     knotwell:~ b rule myredir1 '{ if(http_host == "x.xx.xxx") { redirect to "http://xxx.xxx:80000/dir" }}' 
     knotwell:~ b virtual 192.168.1.222:0 { use rule myredir1 } 
     knotwell:~  
     

    There are two separate commands and the virtual command must be issued *after* the rule command since a rule may not be used prior to its definition. Furthermore, the rule body must be quoted properly.

  • I just tried out this rule on 4.6.2 and it loaded properly.

     if (http_host == "www.company.com") { 
        redirect to "http://www.company.com:5000/dir" 
      } 
      else { 
        discard 
      }

    Also, the following command line version should work:

    bigpipe rule myredir '{if (http_host == "www.mycompany.com") { redirect to "http://www.company.com:5000/dir" }}'

    -Joe
  • bknotwell_12713's avatar
    bknotwell_12713
    Historic F5 Account
    Assumption: www.company.com resolves to the unused ip you've chosen and the resolution to it has a vip as well.

     

     

    If you test the request by hand like I did earlier using telnet, it should be relatively easy to see what's happening.
  • I got it working. Thank you for your help!

     

     

    Besides the syntax for the redirect I needed 2 VIPS. One connected to the rule for the redirect, then a second to the load balancing pool.

     

     

    Have a great day!

     

     

    Cliff Airhart