Forum Discussion
Please 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 504 when attempting to access without "www." and packet capture shows f5 reply with TCP ACK, then RST after GET/ from client. When using "www." page loads fine.
Thanks!
when HTTP_REQUEST {
if { !([string tolower [HTTP::host]] starts_with "www." or "wwwq.") } {
HTTP::redirect [HTTP::host][HTTP::uri] }
}
2 Replies
Looks like it works without the OR. Any assistance on the best way to incorporate that is appreciated.
when HTTP_REQUEST { if { !([HTTP::host] starts_with "www.") } { HTTP::redirect http://www.[HTTP::host][HTTP::uri] } }- JRahm
Admin
you 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
* 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