Forum Discussion
iRule to add www without changing URL
- Jul 05, 2019
Do you want to change Host header sent from the client in server side connection or do you want to redirect the client to https://WWW.abc.com/testfolder/blahblahblah
to redirect the client, use following code
when HTTP_REQUEST { if {[HTTP::host] eq "abc.com"} { HTTP::redirect "https://www.abc.com[HTTP::uri]" } }
you can also do the same with LTM Policy:
rule 1 :
- conditions :
- http-host equals "abc.com"
- http-uri path segment equals /
- actions
- http redirect https://www.abc.com/web/default.aspx
rule 2 :
- conditions :
- http-host equals "abc.com"
- actions
- http redirect tcl:https://www.abc.com[HTTP::uri]
The order in which the irule was placed on the F5 was the issue. After moving the irule to the bottom of the list, it worked! Thanks everyone!
- Lee_SutcliffeJul 09, 2019Nacreous
If you have more than one iRule on a VIP I would seriously recommend using priorities on your events. This way you can control the ordering of your events rather than relating on list ordering which is not ideal.
https://devcentral.f5.com/s/articles/the101-irules-101-events-amp-priorities
when HTTP_REQUEST priority 100 { #this event will fire SECOND } when HTTP_REQUEST priority 10 { #this event will fire FIRST }
- MihirP1129Jul 09, 2019Nimbostratus
Good to know for future reference. Thanks Lee.
- MihirP1129Jul 09, 2019Nimbostratus
@Lee,
We typically have about 5 standard irules for all sites, so would the priority irule look something like this? Start from priority 1 (apply rule first) and works it way up in order?
# is_secure_header
when HTTP_REQUEST priority 3 {
HTTP::header insert IsSecureConnection True
}
# x-Frame-Options
when HTTP_RESPONSE priority 2 {
HTTP::header insert X-FRAME-OPTIONS "SAMEORIGIN"
}
# Cookie_set_HttpOnly_Secure_SameSiteLax
when HTTP_RESPONSE priority 1 {
set unsafe_cookie_headers [HTTP::header values "Set-Cookie"]
HTTP::header remove "Set-Cookie"
foreach set_cookie_header $unsafe_cookie_headers {
HTTP::header insert "Set-Cookie" "${set_cookie_header}; Secure; HttpOnly; SameSite=Lax"
}
}
- Lee_SutcliffeJul 09, 2019Nacreous
Almost. Remember HTTP_REQUEST will always trigger before an HTTP_RESPONSE event, as you cannot have a response before a request.
So “when HTTP_RESPONSE priority 1” will trigger after “when HTTP_REQUEST priority 3”
What I tend to do it place events of the same priority in a single iRule as it makes it easier to read. But that’s just a personal preference.
- MihirP1129Jul 09, 2019Nimbostratus
Ok thanks. Besides manageability, is there any pros to having one "standard" irule with priorities? Is there a performance gain over having multiple single irules?
- Lee_SutcliffeJul 09, 2019Nacreous
No, none at all. When iRules are loaded on the VS, TMOS essentially builds them into a master iRule in memory, it doesn’t execute individual files.
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