I am still very new to iRules, and I am trying to get the code correct for a simple URL redirect. The VS already has an iRule that will redirect traffic from port 80 to 443. Plus, I will need it to work with or without the leading www.
A very basic (host-agnostic) redirect iRule might look something like this (applied to the port 80 VIP):
when HTTP_REQUEST {
HTTP::redirect "https://www.def.123.com[HTTP::uri]"
}
Where [HTTP::uri] is the URI from the original request (if you need to keep that). This will take any request to the VIP and (blindly) redirect it. Or do you only need it to redirect if the requested host value is “abc.com” or “www.abc.com”?
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] ends_with ".abc.com" } {
HTTP::redirect "https://www.def.123.com[HTTP::uri]"
}
}
If this VIP services a single (DNS) resolved host name, then all requests should technically be for abc.com or www.abc.com, and you could skip the HTTP::host evaluation.
I am trying to do something similar to this but I can’t seem to get the re-direct to work. I’m trying to filter based on http_host and http_uri. Here is what I have currently:
when HTTP_REQUEST {
if { [HTTP::host] contains "sandboxcernercentral.com" }{
if { [HTTP::uri] starts_with "/audit-reports/admin/" }{
HTTP::redirect https://associates.sandboxcernercentral.com/sentinel/
}
}
}
You can try this, and by no means am I an expert in this either. If this doesn’t work for you, you may want to post your question as a separate question so one of the experts can help.
when HTTP_REQUEST { if {([HTTP::uri] == “/audit-reports/admin/”) } { log local0. “PATH MATCH / URI: [HTTP::uri] HOST: [HTTP::host]" HTTP::redirect https://associates.sandboxcernercentral.com/sentinel } elseif { ! ([HTTP::host] contains “1800wxbrief”) } { log local0. "PATH MATCH / URI: [HTTP::uri] HOST: [HTTP::host]”
That said, clearly all modern browsers support relative URIs, and indeed the standard that deprecates 2616 (7231) changed this wording to include relative URIs in the Location header.
But, and I’ll quote from a thread on Stackexchange,
“However, until the HTTPbis draft some day becomes the official standard and gets widely adopted, there will always be some new or obscure user agents that implement the current standard to the letter and only accept absolute URLs. Thus, the safe thing to do, for now, is to only use absolute URLs in Location headers…”