Forum Discussion
HTTPS to HTTP Redirection changes required
Below redirection iRule is working for - https://www.my.com
But Not working for https://my.com
Please suggest if there are any changes required
when HTTP_REQUEST { set HOST [string tolower [HTTP::host]] set URI [string tolower [HTTP::uri]]
Start switch host
switch -glob $HOST {
"my.com" - "www.my.com"
{
HTTP::respond 301 Location "http://www.my.com"
}
}
}
2 Replies
- VijayKumarBC_25
Nimbostratus
when HTTP_REQUEST { set HOST [string tolower [HTTP::host]] set URI [string tolower [HTTP::uri]]
Start switch host switch -glob $HOST { "my.it" - "www.my.it" { HTTP::respond 301 Location "http://www.my.it" } }}
- VernonWells
Employee
That rule should work fine. I suggest adding logging. In addition, is there more to the iRule? If not, I recommend strongly against setting
. In fact, it's sub-optimal to set$URI
as a variable, unless it is going to be used more than once. Normally, in programming, coding defensively and optimizing for readability and maintenance efficiency is sensible, but that's not the case with iRules. If one must choose between those things and performance, you almost always want to choose performance, since it executes with each connection (or, in the case of the rule below, each HTTP Request received). Finally, the use of$HOST
on the-glob
should be used only if you intend to perform glob matching. For strict matching, it's about 10% faster to exclude theswitch
. Perhaps give this a try:-globwhen HTTP_REQUEST { switch [string tolower [HTTP::host]] { "my.com" - "www.my.com" { log local0. "Matched HTTP::host = [HTTP::host]" HTTP::respond 301 Location "http://www.my.com" } }Look in
for the log message. If it does not match when you are going to https://my.com, then try the following:/var/log/ltmwhen HTTP_REQUEST { log local0. "Host header = [string tolower [HTTP::host]]" switch [string tolower [HTTP::host]] { "my.com" - "www.my.com" { HTTP::respond 301 Location "http://www.my.com" } }and try the request, again looking in
(be aware that, if the request rate is quite high, the log may be suppressed, and you may end up with a lot of logging!). Once you are done testing, don't forget to remove the logging statements, of course./var/log/ltm
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