Forum Discussion
Removing www and https redirect
I've applied the following iRule to a VIP on port 80. It successfully strips the www if there is one, and then redirects to the VIP on port 443.
I also want to apply this iRule to the VIP on port 443, however that would result in a redirect loop unless I remove the else statement. I'm trying to consolidate and prevent having two different irules per set of VIPs. Is this possible?
when HTTP_REQUEST {
if {([string tolower [HTTP::host]] starts_with "www.")} {
HTTP::redirect "https://[string range [HTTP::host] 4 end][HTTP::uri]"
}
else {
HTTP::redirect https://[HTTP::host][HTTP::uri]
}
}
2 Replies
- Angelo
Nimbostratus
there should be a default i-rule that comes with the F5 that does this no need to write one
- StephanManthey
Nacreous
Hi, you can do the redirect conditionally via "elseif":
when HTTP_REQUEST { if {([string tolower [HTTP::host]] starts_with "www.")} { HTTP::redirect "https://[string range [HTTP::host] 4 end][HTTP::uri]" return } elseif { [TCP::local_port] == 80 } { HTTP::redirect https://[HTTP::host][HTTP::uri] return } }Thanks, Stephan
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
