Forum Discussion
gr0x_33657
Nimbostratus
Nov 03, 2009URI Redirect
Hi,
We would like to redirect all traffic to our maintenance page, so far if someone calls the domain name for example "www.domainname.com" the irule works and redirects the person to "www.domainname.com/maintenance.html" If someone calls "www.domainname.com/sitefolder/" the irule will not work. I tried changing it but the irule will just loop.
when HTTP_REQUEST {
if { [HTTP::path] equals "/" } {
HTTP::redirect "/maintenance.html"
Thanks
- The_Bhattman
Nimbostratus
This is because the you have [HTTP::path] equal "/" which means that it will only redirect when there is no URI in the domain.when HTTP_REQUEST { if { ([HTTP::host] eq "www.domainname.com") and ([HTTP::path] eq "/" } { HTTP::redirect "http://[HTTP::host]/maintenance.html" } }
when HTTP_REQUEST { if {[HTTP::host] eq "www.domainname.com") } { switch -glob [HTTP::path] { "/" { HTTP::redirect "/maintenance.html" } "/sitefolder" { HTTP::redirect "/maintenance.html" } } } }
- gr0x_33657
Nimbostratus
Thanks, your rules work but is it possible to put a wildcard for HTTP::path, we dont want users to surf the website. - The_Bhattman
Nimbostratus
You can use "*/" or "/*" or "/sitefolder*" or "*sitefolder" - The_Bhattman
Nimbostratus
or you can do thiswhen HTTP_REQUEST { if {[HTTP::host] eq "www.domainname.com") } { switch -glob [HTTP::path] { "/" { HTTP::redirect "/maintenance.html" } "/sitefolder" { HTTP::redirect "/maintenance.html" } default { HTTP::redirect "/maintenance.html" } } } }
- gr0x_33657
Nimbostratus
I get a redirection loop error in Firefox. I also tried "/*" but that does not work for me. - hoolio
Cirrostratus
It would be easier to handle if the maintenance page was in a unique directory. You could then check if the requested path started with that directory before redirecting them. This would avoid a redirect loop:when HTTP_REQUEST { Check if URI does not start with "/maintenance" if {not ([HTTP::path] starts_with "/maintenance")}{ HTTP::redirect "/maintenance/maintenance.html" } }
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