Forum Discussion
iRule redirect based on hostname
Looking for some assistance in creating an iRule that would do the following:
User goes to http://one.abc.com/* redirect to http://one.xyz.com/sites/sync/SitePages/Home.aspx
However, if user goes to either of these URL's (same hostname) don't redirect: http://one.abc.com/sites/HR or http://one.abc.com/Pages/AboutMe.aspx
Thanks, Pete
Try something like this:
when HTTP_REQUEST { if {[string tolower [HTTP::host]] equals "one.abc.com"}{ if {not (([string tolower [HTTP::path]] starts_with "/sites/hr") || ([string tolower [HTTP::path]] equals "/pages/aboutme.aspx"))}{ HTTP::redirect "http://one.xyz.com/sites/sync/SitePages/Home.aspx" } } }
https://devcentral.f5.com/wiki/iRules.HTTP.ashx
https://devcentral.f5.com/wiki/iRules.HTTP__host.ashx
- Cory_OCirrus
I'm not sure what version you're running, but have you looked into Local Traffic Policies?
I use them for my HTTP to HTTPS redirects as dictated in this article: https://support.f5.com/csp/article/K26312346
Hope that helps!
-C
- Brad_ParkerCirrus
Try something like this:
when HTTP_REQUEST { if {[string tolower [HTTP::host]] equals "one.abc.com"}{ if {not (([string tolower [HTTP::path]] starts_with "/sites/hr") || ([string tolower [HTTP::path]] equals "/pages/aboutme.aspx"))}{ HTTP::redirect "http://one.xyz.com/sites/sync/SitePages/Home.aspx" } } }
https://devcentral.f5.com/wiki/iRules.HTTP.ashx
https://devcentral.f5.com/wiki/iRules.HTTP__host.ashx
- hooleylistCirrostratus
You can use a switch statement to avoid setting the HTTP::path value to lowercase twice:
when HTTP_REQUEST { if {[string tolower [HTTP::host]] equals "one.abc.com"}{ switch [string tolower [HTTP::path]] { "/sites/hr" - "/pages/aboutme.aspx" { Do nothing and allow request to go to virtual server default pool } default { For all other requests, redirect to new URL HTTP::redirect "http://one.xyz.com/sites/sync/SitePages/Home.aspx" } } } }
- Pete_Paiva_7147Nimbostratus
Brad - that worked, thanks so much for the help!!
Cory - I haven't done much with local traffic policies but I'll take a look at that for any future requests.
- Pete_Paiva_7147Nimbostratus
Brad - one more request if you don't mind.
Can you help me with the syntax to to add the following 2 additional sites to the iRule? Basically, don't redirect for these additional 2 sites:
http://one.abc.com/pub/ http://one.abc.com/sites/sa
I'm using this iRule:
when HTTP_REQUEST { if {[string tolower [HTTP::host]] equals "one.abc.com"}{ if {not (([string tolower [HTTP::path]] starts_with "/sites/hr") || ([string tolower [HTTP::path]] equals "/pages/aboutme.aspx"))}{ HTTP::redirect "; } } }
- Brad_Parker_139Nacreous
Try something like this:
when HTTP_REQUEST { if {[string tolower [HTTP::host]] equals "one.abc.com"}{ if {not (([string tolower [HTTP::path]] starts_with "/sites/hr") || ([string tolower [HTTP::path]] equals "/pages/aboutme.aspx"))}{ HTTP::redirect "http://one.xyz.com/sites/sync/SitePages/Home.aspx" } } }
https://devcentral.f5.com/wiki/iRules.HTTP.ashx
https://devcentral.f5.com/wiki/iRules.HTTP__host.ashx
- hooleylistCirrostratus
You can use a switch statement to avoid setting the HTTP::path value to lowercase twice:
when HTTP_REQUEST { if {[string tolower [HTTP::host]] equals "one.abc.com"}{ switch [string tolower [HTTP::path]] { "/sites/hr" - "/pages/aboutme.aspx" { Do nothing and allow request to go to virtual server default pool } default { For all other requests, redirect to new URL HTTP::redirect "http://one.xyz.com/sites/sync/SitePages/Home.aspx" } } } }
- Pete_Paiva_7147Nimbostratus
Brad - that worked, thanks so much for the help!!
Cory - I haven't done much with local traffic policies but I'll take a look at that for any future requests.
- Pete_Paiva_7147Nimbostratus
Brad - one more request if you don't mind.
Can you help me with the syntax to to add the following 2 additional sites to the iRule? Basically, don't redirect for these additional 2 sites:
http://one.abc.com/pub/ http://one.abc.com/sites/sa
I'm using this iRule:
when HTTP_REQUEST { if {[string tolower [HTTP::host]] equals "one.abc.com"}{ if {not (([string tolower [HTTP::path]] starts_with "/sites/hr") || ([string tolower [HTTP::path]] equals "/pages/aboutme.aspx"))}{ HTTP::redirect "; } } }
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