Forum Discussion
If incomming URL does not have specific URI's then redirect to external website
For this application, if an HTTP request doesn't come in with certain specific URI's then we want to redirect it to this Content Management front end in the cloud. I tried doing it this way:
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/fmstorefront"} {pool qa.fmmpe-cat.com_80} elseif { [HTTP::uri] starts_with "/medias"} {pool qa.fmmpe-cat.com_80} elseif { [HTTP::uri] starts_with "/fmwebservice"} {pool qa.fmmpe-cat.com_80} elseif { [HTTP::uri] starts_with "/ipows"} {pool qa.fmmpe-cat.com_80} else { HTTP::redirect "; return } }
Now the first 3 elseif could be done better, but this seems to work for now. It's the ELSE that isn't working. When I do this right now, I should get a NOT FOUND from the remote site (as its not up yet) but I'm getting "This site can't be reached"
Any suggestions?
2 Replies
- Vijay_E
Cirrus
When posting iRule, please use formatting for ease of reading. This is your iRule:
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/fmstorefront"} { pool qa.fmmpe-cat.com_80 } elseif { [HTTP::uri] starts_with "/medias"} { pool qa.fmmpe-cat.com_80 } elseif { [HTTP::uri] starts_with "/fmwebservice"} { pool qa.fmmpe-cat.com_80 } elseif { [HTTP::uri] starts_with "/ipows"} { pool qa.fmmpe-cat.com_80 } else { HTTP::redirect "https://d2ipxxe5h4s25e.cloudfront.net" } }I would recommend using a datagroup like this as there is a common pool for the matches URI:
when HTTP_REQUEST { if { [class match [HTTP::uri] starts_with CLASS_URI] } { pool qa.fmmpe-cat.com_80 } else { HTTP::redirect "https://d2ipxxe5h4s25e.cloudfront.net" } }CLASS_URI is a datagroup.
Or use the switch statement.
when HTTP_REQUEST { switch -glob [string tolower [HTTP::uri]] { "/fmstorefront*" - "/medias*" - "/fmwebservice*" - "/ipows*" { pool qa.fmmpe-cat.com_80 } default { HTTP::redirect "https://d2ipxxe5h4s25e.cloudfront.net" } } }
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