Forum Discussion
Domain Redirect iRule
All, Having issues with setting up irule to redirect any host equals with URL = / to redirect to the home page, then allowing anything coming over with /* to maintain the full path. Seems pretty straight forward, but I can't get the /* of the irule to take affect. Would appreciate any help with this. Probably something easy I am missing.
Thanks, Bryce
Existing iRule when HTTP_REQUEST { Domain 301 Redirect if { ([HTTP::host] equals "www.blah.com" ) or ([HTTP::host] equals "10.10.10.10") or ([HTTP::host] equals "blah.com") } { if { ([HTTP::uri] equals "/") } {
HTTP::respond 301 Location "http://www.blah.com/home/index.jsp" } }
Tried to implement the following with no success when HTTP_REQUEST { Domain 301 Redirect if { ([HTTP::host] equals "www.blah.com" ) or ([HTTP::host] equals "10.10.10.10") or ([HTTP::host] equals "blah.com") } { if { ([HTTP::uri] equals "/") } {
HTTP::respond 301 Location "http://www.blah.com/home/index.jsp" elseif { ([HTTP::uri] equals "/*") } { HTTP::respond 301 Location "http://www.blah.com[HTTP::uri} } }
2 Replies
- Kevin_Stewart
Employee
The equals operator doesn't support a wildcard match. But nevertheless:
} elseif { not ( [HTTP::uri] equals "/" ) } { HTTP::respond 301 Location "http://www.blah.com[HTTP::uri]" }would create an infinite loop for any traffic that wasn't just "/". Important to observe of course that in the absence of a URI path in the browser, HTTP::uri will still return "/". So the first iRule didn't work?
when HTTP_REQUEST { if { [HTTP::uri] equals "/" } { HTTP::redirect ... } }This explicitly states that if the URI path is nothing/empty, then redirect, and implies that anything else be allowed through. You may otherwise not be meeting the HTTP::host qualifications.
- Stanislas_Piro2
Cumulonimbus
Hi, there are multiple syntax errors in the irule.
try the following irules:
when HTTP_REQUEST { Domain 301 Redirect if { ([HTTP::host] equals "www.blah.com" ) or ([HTTP::host] equals "10.10.10.10") or ([HTTP::host] equals "blah.com") } { if { ([HTTP::uri] equals "/") } { HTTP::respond 301 Location "http://www.blah.com/home/index.jsp" } elseif { !([HTTP::host] equals "www.blah.com") } { HTTP::respond 301 Location "http://www.blah.com[HTTP::uri] } } }or use a switch command:
when HTTP_REQUEST { switch -glob [string to lower [HTTP::host][HTTP::path]] { "www.blah.com/" - "blah.com/" - "10.10.10.10/" {HTTP::respond 301 Location "http://www.blah.com/home/index.jsp"} "blah.com/*" - "10.10.10.10/*" {HTTP::respond 301 Location "http://www.blah.com[HTTP::uri]"} } }
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