Forum Discussion
An http redirect irule that is executing but not actually redirecting
This is my first attempt at implementing an irule. I've written a few variations trying to get something to work. I've included them all below (replacing the sensitive values with xxx). The result is the same: each of the rules below execute when I load a page with "xxx" in the URL (can see the number of executions increasing in the statistics area), but the redirect doesn't happen. The F5 irule editor reports that the syntax for each is valid.
when HTTP_REQUEST { if { [HTTP::uri] contains "xxx"} { HTTP::redirect "" } }
when HTTP_REQUEST { if { [HTTP::uri] contains "xxx"} { HTTP::redirect "[HTTP::uri]" } }
when HTTP_REQUEST { if { [HTTP::uri] contains "xxx"} { HTTP::redirect } }
7 Replies
- Stanislas_Piro2
Cumulonimbus
the condition {[HTTP::uri] contains "xxx"} is case sensitive.
to convert URI to lowercase, the condition must be: {[string tolower [HTTP::uri]] contains "xxx"}
of course, configure xxx with only lowercase...
- THi
Nimbostratus
It is a fairly easy to add debugging info to the iRules when developing them. You can add logging within the if-clause to see if the condition is met. (
-style).log local0. "Kilroy was here.."Then check the ltm log.
tail -f /var/log/ltm from command line would give you real time view what is appended to the log. Also have you checked for any run time TCL errors in the ltm log?
- nathe
Cirrocumulus
what happens if you use HTTP Fox or Fiddler, do you see the redirect happen here, even if it fails? This might give you a clue as to what's going on, or not.
- casieowen_20826
Nimbostratus
I'm not seeing anything useful in fiddler. Attaching a snip. I replaced the dns name with xxx. So, in the snip, where you see xxx is exactly the text in the "xxx" in the irule. The destination pages load Dundas dashboards. I'm trying to redirect any hits with "xxx" to a specific dashboard URL. What's happening instead is, it's loading the default Dundas admin pages rather than redirecting to a specific dashboard.
- THi
Nimbostratus
From the fiddler: xxx is host part of the request. HTTP::uri is the URI part of the URL. Ie. path and parameters - and does not contain host. Try URI::host or HTTP::host instead.
From iRules wiki:
HTTP::uri Returns or sets the URI part of the HTTP request. For the following URL: http://www.example.com:8080/main/index.jsp?user=test&login=check The URI is: /main/index.jsp?user=test&login=check URI::host Returns the host portion of a given URI. URI::host HTTP::host¶ Returns (or sets in v11.5+) the value of the Host header of an HTTP request. - casieowen_20826
Nimbostratus
Thanks for sticking with this. Here's where I'm at currently.
If I use the irule below
when HTTP_REQUEST { if { [http::host] contains "xxx"} { HTTP::redirect "" } }
without a host header entry for the site, I get an immediate page cannot be displayed and a corresponding execution and failure in statistics for the rule on the F5 web UI.
If I add xxx as the host header (xxx as the host name in the bindings for All unassigned IPs or for the IP for the site), it takes a long while, then I get a paged cannot be displayed error, and no failure indicated in statistics (execution is indicated, but no failure).
With the rule disabled (not associated to the VIP):
I cannot load the page I'm trying to redirect to by hitting it directly if xxx is a host header (as defined above).
The only way I can load the page I'm trying to redirect to by hitting the url directly is if there is no host header (as defined above) and without this irule.
Any ideas?
- Kevin_Stewart
Employee
If I can jump in here, when a modern browser makes an HTTP request to a site using an odd port (ie. not port 80 for HTTP and 443 for HTTPS), that port becomes part of the Host header. Example:
when HTTP_REQUEST { log local0. [HTTP::host] }Testing from cURL:
curl http://test.domain.com:88Log result:
: test.domain.com:88When you talk about host name binding, are you talking about the web server configuration, as in Host header binding in IIS? If so, it's very likely that you need to specify the port as part of that Host header.
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