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]
- MihirP1129Jul 09, 2019Nimbostratus
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"
}
}
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