Forum Discussion
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
- Brad_Parker_139
Nacreous
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]" } }- MervLama_235015
Nimbostratus
Thanks Brad - I will give it a try and feedback
- Brad_Parker
Cirrus
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]" } }- MervLama_235015
Nimbostratus
Thanks Brad - I will give it a try and feedback
- Stanislas_Piro2
Cumulonimbus
The best solution is to create the new statement in the existing irule.
the Location header can contain only URI or all URL
- /ioks/ --> OK
- https://www.test2.co.uk/ioks/ --> OK
but not hostname without protocol :
- www.test2.co.uk/ioks/ --> WRONG
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]" }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com