Forum Discussion
iRule redirect based on hostname
- Jul 24, 2017
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
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
- hooleylistJul 25, 2017Cirrostratus
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_7147Jul 25, 2017Nimbostratus
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_7147Jul 27, 2017Nimbostratus
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_ParkerJul 31, 2017Cirrus
So the best ways to accomplish this is to either use a variant of Hoolio's suggestion of using a switch like this:
when HTTP_REQUEST { if {[string tolower [HTTP::host]] equals "one.abc.com"}{ switch -glob [string tolower [HTTP::path]] { "/sites/hr/*" - "/pages/aboutme.aspx" - "/pub/*" - "/sites/sa/*" { 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" } } } }
Or if you plan to add additional URLs in the future the use of a data group would probably be better so you don't have to edit the rule, just add entries to your data group:
when HTTP_REQUEST { if {[string tolower [http::host]] equals "one.abc.com"}{ if{not ([class match [string tolower [HTTP::path]] starts_with "/Common/dont_redirect_dg"])}{ HTTP::redirect "http://one.xyz.com/sites/sync/SitePages/Home.aspx" } } }
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