Forum Discussion
kaviraj_Daboo_1
Nimbostratus
Jul 04, 2013HTTP-HTTPS redirection
Hello,
Kevin_Stewart
Employee
Jul 10, 2013I'm not so concerned with the protocol (HTTP vs. HTTPS) but any redirects that may be coming directly from the server. In my Apache lab I noticed 301 redirects coming back for URIs that didn't end with "/". Example:
URI = "/y/z" - redirect to "http://test.domain.com/y/z/"
It was this behind-the-scenes redirect that was throwing things off. So I modified the above iRule slightly:
when HTTP_REQUEST {
if { [string tolower [HTTP::host]] equals "test.domain.com" } {
switch -glob [string tolower [HTTP::uri]] {
"/y/z/*" {
return
}
"/y/z" {
HTTP::uri "[HTTP::uri]/"
return
}
"/y/*" {
if { [TCP::local_port] ne "443" } {HTTP::redirect "https://[HTTP::host][HTTP::uri]" }
}
"/y*" {
if { [TCP::local_port] ne "443" } {HTTP::redirect "https://[HTTP::host][HTTP::uri]" }
}
"/*" {
if { [TCP::local_port] ne "80" } { HTTP::redirect "http://[HTTP::host][HTTP::uri]" }
}
default {
drop
}
}
}
}
I'm now accounting for the missing trailing "/" in the request and preventing the server from sending it (erroneously).
====================
...
"/y/z" {
HTTP::uri "[HTTP::uri]/"
return
}
...
====================
Give that a shot.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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