Forum Discussion

MervLama_235015's avatar
MervLama_235015
Icon for Nimbostratus rankNimbostratus
Nov 20, 2015

iRule redirect from sports.test.co.uk/ioks/* to www.test.co.uk/ioks/*

Hi I wonder if you can assist me on this. I need to write an iRule to redirect incoming traffic from sports.test.co.uk/ioks/* to www.test2.co.uk/ioks/*

 

The VIP has already an iRule redirection on it for something else. So shall I just modify the existing iRule by inserting a new statement or shall I create another iRule (not sure if two different redirection iRules can exist on the same VIP).

 

Please advise, below are the statements please let me know if they are correct? Many thanks

 

OPTION 1: Modify existing Irules insert

 

elseif {[HTTP::uri] starts_with "/ioks/"} { HTTP:: respond 301 Location "www.test2.co.uk/ioks/" log local0. "This is iojs [HTTP::uri]"

 

}

 

OPTION 2: Create a new Irule

 

when HTTP_REQUEST { if {[HTTP::uri] starts_with "/ioks/"} { HTTP::redirect "www.test2.co.uk/ioks/"} }

 

5 Replies

  • You can use either strategy, but if there is a specific order you want them to be processed there is a consideration. If you added it to the existing rule you can definitely order the evaluation like you did above with an elseif. If you wanted a specific processing order with putting it in a new iRule you would want to use priority. https://devcentral.f5.com/wiki/iRules.priority.ashx. Also, if you want to retain the full URI you will have to do something like below. Below if the new iRule with a lower priority so it will be evaulated after the first iRules HTTP_REQUEST.

    when HTTP_REQUEST priority 600 {
        if { [string tolower [HTTP::uri]] starts_with "/ioks/"}{
            HTTP::respond 301 noserver Location "https://www.test2.com[HTTP::uri]"
        }
    }
    
  • You can use either strategy, but if there is a specific order you want them to be processed there is a consideration. If you added it to the existing rule you can definitely order the evaluation like you did above with an elseif. If you wanted a specific processing order with putting it in a new iRule you would want to use priority. https://devcentral.f5.com/wiki/iRules.priority.ashx. Also, if you want to retain the full URI you will have to do something like below. Below if the new iRule with a lower priority so it will be evaulated after the first iRules HTTP_REQUEST.

    when HTTP_REQUEST priority 600 {
        if { [string tolower [HTTP::uri]] starts_with "/ioks/"}{
            HTTP::respond 301 noserver Location "https://www.test2.com[HTTP::uri]"
        }
    }
    
  • The best solution is to create the new statement in the existing irule.

     

    the Location header can contain only URI or all URL

     

    but not hostname without protocol :

     

    So the right code is (URI is added in the Location header as your question contains wildcard):

     

    elseif {[HTTP::path] starts_with "/ioks/"} { 
        HTTP:: respond 301 Location "http://www.test2.co.uk[HTTP::uri]" 
        log local0. "This is iojs [HTTP::uri]"
    }