Forum Discussion
Chris_123510
Nimbostratus
Sep 17, 2013Simple URL redirect iRule
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 w...
Kevin_Stewart
Employee
Sep 17, 2013A 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.
Recent Discussions
Related Content
DevCentral Quicklinks
* 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
Discover DevCentral Connects