Forum Discussion
brettbeggs_1177
Nimbostratus
Apr 07, 2010iRule Request - strip sub domains
I'm trying to create an iRule that can be used similar to the following mod rewrite command:
RewriteCond %{HTTP_HOST} ^.+\.(.+)\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ https://%1.mydoma...
hoolio
Cirrostratus
Apr 08, 2010Hi Brett,
I tried a regex, but it was about 10x less efficient than a couple of string and list operations:
Simple perf test:
% time {set host_list [split $host "."]; lindex $host_list [expr {[llength $host_list] -3}]} 1000
13 microseconds per iteration
% time {regexp -inline -nocase {(?:[^.]+\.){0,}([^.]+)\.mydomain\.com} test.mydomain.com} 1000
133 microseconds per iteration
when HTTP_REQUEST {
log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] request to [HTTP::host][HTTP::uri]"
Split the host header value on periods into a list
set host_list [split [HTTP::host] "."]
log local0. "[IP::client_addr]:[TCP::client_port]: Parsed host list $host_list"
Check if there were more than three fields
if {[llength $host_list] > 3}{
Send a redirect with the third to last field from the requested host prepended to .mydomain.com
HTTP::respond 301 Location "https://[lindex $host_list [expr {[llength $host_list] -3}]].mydomain.com"
log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting to\
https://[lindex $host_list [expr {[llength $host_list] -3}]].mydomain.com"
}
}
Aaron
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