Forum Discussion
mike_gatti_6169
Nimbostratus
May 17, 2007Using array/class to define veriable and use for redirect
I have been trying to use an array or class to define a variable that will be used for a redirect. The iRule that I have created (and not working) is:
when RULE_INIT {
array set sites {
/site1
/site2
}
}
when HTTP_REQUEST {
if { [HTTP::uri] starts_with $::sites] } {
HTTP::redirect "http://www.domain.com/global/[string range [HTTP::uri] 1 end]"
}
elseif { [HTTP::uri] starts_with "/global" } {
use pool site_pool
}
}
I am new to TCL and not sure if this is correct.
----------------------------------------------------
I also tried to use class and got a syntax error.
when RULE_INIT {
class sites {
“/site1”
“/site2”
}
}
when HTTP_REQUEST {
if { [HTTP::uri] starts_with $::sites] } {
HTTP::redirect "http://www.domain.com/global/[string range [HTTP::uri] 1 end]"
}
elseif { [HTTP::uri] starts_with "/global" } {
use pool site_pool
}
}
Trying this I received a syntax error:
[undefined procedure: class] [class sites {
“/site1”
“/site2”
}
Any help is very welcome.
Thanks
Mike
- mike_gatti_6169
Nimbostratus
Some additional information, - A couple of common mistakes.
when RULE_INIT { set sites [list \ "/site1" \ "/site2" \ ] } when HTTP_REQUEST { if { [matchclass [HTTP::uri] starts_with $::sites] } { HTTP::redirect "http://www.domain.com/global/[string range [HTTP::uri] 1 end]" } elseif { [HTTP::uri starts_with "/global" } { pool site_pool } }
when HTTP_REQUEST { switch -glob [HTTP::uri] { "/site1*" - "/site2*" { HTTP::redirect "http://www.domain.com/global/[string range [HTTP::uri] 1 end]" } "/global*" { pool site_pool } } }
- mike_gatti_6169
Nimbostratus
1st, thanks much for the help, - André_Bentes_45
Nimbostratus
how do i create an https_request and an http_request class or data group? - dennypayne
Employee
Posted By andre.bentes@reallife.pt on 04/23/2009 10:36 AM
- Thomas_Schaefer
Nimbostratus
I'm not sure if this is what you are after but I have an Initialize iRule fire first (using priority) to determine if the request is https or not.when HTTP_REQUEST priority 5 { log local0. "In Initialize" if {[TCP::local_port] == 443} { set ::ghttp_protocol "https\:" } else { set ::ghttp_protocol "http\:" } }
HTTP::redirect "$::ghttp_protocol//www.domain.com..."
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