Forum Discussion
Portable root domains redirects
Hi, We're looking to redirect a bunch of domains from "root" requests to "www". The rule has to allow additional subdomains through, but be portable for many root domains.
My idea is to split the HTTP::host on "." and count the resulting list. If it's less than 2, append "www." to HTTP::host and redirect.
Sound reasonable? Any better ideas?
Thanks! Ben
4 Replies
- Kevin_Stewart
Employee
Try this:
when HTTP_REQUEST { if { [llength [split [HTTP::host] "."]] < 3 } { HTTP::redirect "http://www.[HTTP::host][HTTP::uri]" } } - Kevin_Stewart
Employee
You can do something like this:
when HTTP_REQUEST { set proto "http://" if { [PROFILE::exists clientssl] == 1] } { set proto "https://" } if { [llength [split [HTTP::host] "."]] < 3 } { HTTP::redirect "${proto}www.[HTTP::host][HTTP::uri]" } } - John_Ogle_45372
Nimbostratus
Kevin,
I can't get that last iRule to paste without errors on my 11.3 box. It looks fine but complains of token errors. Thoughts?
01070151:3: Rule [/Common/Redirect_Root_Domains_keep_protocol] error: line 3: [parse error: PARSE syntax 85 {syntax error in expression " [PROFILE::exists clientssl] == 1] ": extra tokens at end of expression}] [{ [PROFILE::exists clientssl] == 1] }] line 6: [parse error: PARSE syntax 173 {syntax error in expression " [llength [split [HTTP::host] "."]] < 3 ": variable references require preceding $}] [{ [llength [split [HTTP::host] "."]] < 3 }]
- Kevin_Stewart
Employee
I had an extra square bracket in there. Try this:
when HTTP_REQUEST { set proto "http://" if { [PROFILE::exists clientssl] == 1 } { set proto "https://" } if { [llength [split [HTTP::host] "."]] < 3 } { HTTP::redirect "${proto}www.[HTTP::host][HTTP::uri]" } }
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