Forum Discussion
IRule Redirect URL to other URL for maintenance
If you are running 11.4 or higher, then I recommend using a Local Traffic Policy:
I assume that you only want requests for '/' to redirect. If so, the Local Traffic Policy definition is:
ltm policy maintenance_redirect {
controls { forwarding }
requires { http }
rules {
rule01 {
actions {
0 {
http-reply
redirect
location /app_offline_abd.htm
}
}
conditions {
0 {
http-host
host
values { branch.com }
}
1 {
http-uri
path
values { / }
}
}
ordinal 1
}
}
strategy first-match
}
If you want any URI path to redirect there:
ltm policy foo {
controls { forwarding }
requires { http }
rules {
rule01 {
actions {
0 {
http-reply
redirect
location /app_offline_abd.htm
}
}
conditions {
0 {
http-host
host
values { branch.com }
}
1 {
http-uri
path
not
values { /app_offline_abd.htm }
}
}
ordinal 1
}
}
strategy first-match
}
This redirects a request for anything but the target of the redirection.
Either of these can be loaded by saving them to a file on the BIG-IP (say, /var/tmp/mr.txt) and merging them into the configuration:
tmsh load sys config file /var/tmp/mr.txt merge
When you want to utilize the policy, apply it to the appropriate Virtual Servers (in the Web UI, select the Virtual Server, then "Resources" at the top).
If you are using a version before 11.4, you can employ an HTTP Class:
- (SOL7280: Overview of the HTTP Class profile)[https://support.f5.com/kb/en-us/solutions/public/7000/200/sol7280.html]
There's no particular need or advantage to using an iRule for this case, but if you decide that is what you want, then:
when HTTP_REQUEST {
if { [HTTP::host] eq "branch.com" and [HTTP::path] eq "/" } {
HTTP::redirect "/app_offline_abd.htm"
}
}
or, to redirect everything:
when HTTP_REQUEST {
if { [HTTP::host] eq "branch.com" and [HTTP::path] ne "/app_offline_abd.htm" } {
HTTP::redirect "/app_offline_abd.htm"
}
}
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