Forum Discussion
Steve_Manuel_11
Nimbostratus
Oct 06, 2006http/https redirect
Hello everyone;
I'm trying to do a simple http https redirect for a VSA.
Before
http://cms-d3.tmi.telus.com
looking to see
https://cms-d3.tmi.telus.com
I found the code sample
when HTTP_REQUEST {
HTTP::redirect https://[getfield [HTTP::host] ":" 1][HTTP::uri]
}
and created an iRule called HTTP_HTTPS_REDIRECT. I attached this iRule to the VSA
My ultimate end state is to add the this functionality to my URI parse rule
RULE NAME: D3_INT1_CMS_SECURE_REDIRECT
VERSION : 1.0
DESC : CMS (Documentum) Secure Redirects
when HTTP_REQUEST {
set uri [HTTP::uri]
Extract first element after slash in URIset
set target [getfield [HTTP::uri] "/" 2]
To perform redirect
Check if the field doesn't contain a dot
Check if the uri doesn't contain the field followed by a slash
Check if http request and redirect to https
if { [HTTP::uri] starts_with "/da/" } {
pool D3_INT1_CMS
}
elseif { [HTTP::uri] starts_with "/webtop/" } {
pool D3_INT1_CMS
}
elseif { [HTTP::uri] starts_with "/woh/" } {
pool D3_INT1_CMS
}
elseif { [HTTP::uri] starts_with "/wp/" } {
pool D3_INT1_CMS
}
elseif { not ( $target contains ".") and not ([HTTP::uri] contains "${target}/") } {
HTTP::redirect "https://[HTTP::host]/${target}/"
}
elseif { [HTTP::uri] starts_with "http://cms" } {
HTTP::redirect "https://cms-d3.tmi.telus.com"
}
else { pool D3_INT1_CONTENT
}
}
Thx
Steve
- Deb_Allen_18Historic F5 AccountHi Steve -
2) A couple of things make me wonder if you are expecting to see the protocol scheme & hostname as part of the output of [HTTP::uri]. URI means the part /after/ the hostname, including the leading slash. For example, in "http://host.domain.com/uri", the URI is "/uri", and the hostname is "host.domain.com". [HTTP::host] is the command to use for comparison with the hostname in the request.set uri [string tolower [HTTP::uri]] ... if {$uri starts with "/da/"}{ ...
which would use the following class list:when HTTP_REQUEST { set uri_first [getfield [string tolower [HTTP::uri]] "/" 2] if {[matchclass $uri_first equals $::CMS_uris]}{ pool D3_INT1_CMS } elseif { not ( $uri_first contains ".") and not ([HTTP::uri] contains "${uri_first}/") } { HTTP::redirect "https://[HTTP::host]/${target}/" } elseif {[string tolower [HTTP::host]] starts_with "cms"} { HTTP::redirect "https://cms-d3.tmi.telus.com" } else { pool D3_INT1_CONTENT } }
class CMS_uris { "da" "webtop" "woh" "wp" }
- Deb_Allen_18Historic F5 AccountHi Steve -
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