Forum Discussion
http header and uri redirect
Hello, I'm attempting to construct an iRule that looks at a header and URI, then performs a redirect if they match. This is what I've attempted but unsuccessful. I have multiple redirects based on different headers and URI's, but this is a base of what I need to get started. Thanks in advance.
when HTTP_REQUEST { switch -glob [string tolower [HTTP::header]] contains "www.yahoo.com" and [HTTP::uri]] equals "/news" - "/weather" { HTTP::redirect "https://www.yahoo.com/login.aspx=0" } else { when HTTP_REQUEST { switch -glob [string tolower [HTTP::header]] contains "www.google.com" and [HTTP::uri]] equals "/news" - "/weather" { HTTP::redirect "https://www.google.com/login.aspx=0" } } }
2 Replies
- cjunior
Nacreous
Hi,
Maybe I did not understood well, but, as you mentioned "multiple headers", have you a list of header names or you intend to look at any of them? I think I would do like this:when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/news*" - "/weather*" { foreach name [list MyHeader1 MyHeader2 MyHeaderN] { switch -glob [string tolower [HTTP::header $name]] { "*www.yahoo.com*" { HTTP::redirect "https://www.yahoo.com/login.aspx=0" return } "*www.google.com*" { HTTP::redirect "https://www.google.com/login.aspx=0" return } } } } } }or this for any header names:
when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/news*" - "/weather*" { foreach name [HTTP::header names] { switch -glob [string tolower [HTTP::header $name]] { "*www.yahoo.com*" { HTTP::redirect "https://www.yahoo.com/login.aspx=0" return } "*www.google.com*" { HTTP::redirect "https://www.google.com/login.aspx=0" return } } } } } }I'm not sure if that was what you wanted, anyway, I hope it helps you in some way.
Hi VFB,
could it be that you wanna parse the HOST-header for a given site name and then apply some redirects based on the a given URI? If so then this code would do the trick...
when HTTP_REQUEST { switch -exact -- [string tolower [HTTP::host]] "www.yahoo.com" { switch -exact -- [string tolower [HTTP::uri]] "/news" - "/weather" { HTTP::redirect "https://www.yahoo.com/login.aspx=0" } default { do nothing } } "www.google.com" { switch -exact -- [string tolower [HTTP::uri]] "/news" - "/weather" { HTTP::redirect "https://www.google.com/login.aspx=0" } default { do nothing } } default { do nothing } }BTW: If not, then elaborate some additional details on the "header" you want to parse.
Cheers, Kai
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
