Forum Discussion
CraigD1_147916
Cirrus
Nov 13, 2015Please assist with redirect to prepend "www."
Hi, I am hoping someone can review my irule to determine why I get no redirection from it when.
I am attempting to prepend www. in any case where it does not already exist.
Fiddler shows 5...
JRahm
Admin
Nov 13, 2015you need to specify the action for both conditions. string tolower is not necessary on the host as it is case insensitive according to the RFC. This should work for you:
when HTTP_REQUEST {
if { [llength [split [HTTP::host] "."]] < 3 } {
HTTP::redirect http://www.[HTTP::host][HTTP::uri]
}
}
This splits the host by the period. If the list is only two items long, then it doesn't have the www before domain.com and redirects.
Example:
% set x "domain.com"
domain.com
% set y "www.domain.com"
www.domain.com
% if { [llength [split $x "."]] < 3 } { puts "prepend" } else { puts "all good" }
prepend
% if { [llength [split $y "."]] < 3 } { puts "prepend" } else { puts "all good" }
all good
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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