Forum Discussion
iRule Shenanigans - My Brain hurts
- Feb 13, 2023
JustCooLpOOLe I see the issue with your iRule and it's both in the if statement and switch statement. For the if statement where you look at the HTTP::host you are matching it to "/" which will never match because host names do not have a "/" in them. The issue with the switch statement is that you are not matching against any particular value denoted by "switch {" which isn't matching against anything in particular. Based on the iRule that you have in place it doesn't seem as though you are matching on a host at all and are just concerned with the URI path so the following iRule should work for you. In conjunction with this iRule you should consider configuring a OneConnect profile so that every HTTP request is passed through the iRule rather than just the initial HTTP request when the TCP connection is formed. I would also like to note that the iRule that you provided does not match what you put in your original post so if what I have provided this time doesn't meet your needs could you provide additional information on what you are attempting to achieve?
when HTTP_REQUEST priority 500 { set HOST [HTTP::host] set URI [string tolower [HTTP::uri]] switch -glob -- ${URI} { "/" { HTTP::redirect 301 Location "https://${HOST}/mainpage.html" } "/mainpage.html" { HTTP::respond 200 content [ifile get "mainpage.html"] } "/mylogo.jpg" { HTTP::respond 200 content [ifile get "mylogo.html"] } default { drop } } }
Paulius I tested this out in my lab and it worked as expected. I did have to remove "301 Location" as it gave me errors when trying to add the irule. I'm on version 16.1.3.2 if it makes any difference.
JustCooLpOOLe I'm glad it worked and excuse my error for the "HTTP::redirect", I had it stuck in my head that it said "HTTP::respond" which you should include the redirect type and location where "HTTP::redirect" automatically responds with a 302.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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