Forum Discussion
IRule Redirect URL to other URL for maintenance
Hi All,
I need help how to redirect http(s)://branch.com to https://branch.com/app_offline_abd.htm. I want the clients from external (public) and internal to redirect the URL https://branch.com/app_offline_abd.htm during maintenance. Both are using virtual server and pool members.
Thanks in advance.
- VernonWellsEmployee
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" } }
- Albert_59847Nimbostratus
Hi vernon,
Thanks for your quick response, sorry to say I am not good in iRule and Policy. I tried to configure in Local Traffic/Policy but I don't understand how it works and below their is add button. I think this will you play the condition and action but I am lost. I want to learn the policy as I am not a script/programmer to play with irule stuff but it seems it is short-cut in the irule as you have presented in above post. But again you said no particular need or advantage using iRule.
In the policy, you have created ltm policy maintenance_redirect and ltm policy foo these two should merge? I will try again the configuration in GUI.
- Albert_59847Nimbostratus
Hi Vernon,
In my virtual server resources I have irule (redirect) should I removed this while adding the policies? Because I never tried both Irule and Polices to manage in resources. In addition, I checked the cli config it doesn't match to your script. I don't know why the action and conditions is missing I did config in GUI.
ltm policy branch_Maintenance_Policy { controls { forwarding } requires { http tcp } rules { Ebranch_Maintenance_Rule { ordinal 1 } } strategy all-match }
- Albert_59847Nimbostratus
Hi Vernon,
I think I get it right, I am just waiting for approval to test this and update you.
ltm policy branch_Maintenance_Policy { controls { forwarding } requires { http tcp } rules { branch_Maintenance_Rule { actions { 0 { http-reply redirect location /app_offline_abd.htm } } conditions { 0 { http-host host values { branch.com.sa } } } ordinal 1 } } strategy all-match }
- VernonWellsEmployee
For your policy you do need a negative matcher for /app_offline_abd.htm, or it will give you a redirect for that page, too. That's condition 1 in my policy foo:
1 { http-uri path not values { /app_offline_abd.htm } }
Other than that, your policy looks right to me.
- Albert_59847Nimbostratus
Hi vernon,
At last I did test the above example that you have shared ......... It works :)
Thank you much.
Regards,
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