Forum Discussion
sparky_86686
Nimbostratus
Nov 19, 2008Using "matching" on Rewrite Redirects
In post 13907 Deb mentions that for the Rewrite Redirects functionality in the http profile:
* Matching: Specifies that the system rewrites the scheme to HTTPS in any HTTP redirect responses in...
hoolio
Cirrostratus
Nov 24, 2008Hi there,
I think that's a slight mis-statement. I'm pretty sure the host in the redirect location is not checked against the request. The 9.4.5 and 9.3.1 online help shows:
Redirect Rewrite
Specifies whether the system rewrites the URIs that are part of HTTP redirect (3XX) responses. The default is None.
* None: Specifies that the system does not rewrite the URI in any HTTP redirect responses.
* All: Specifies that the system rewrites the URI in all HTTP redirect responses.
* Matching: Specifies that the system the URI in any HTTP redirect responses that match the request URI.
* Nodes: Specifies that if the URI contains a node IP address instead of a host name, the system changes it to the virtual server address.
If you want to rewrite the redirect to https if the host in the Location header matches a predefined host you could hardcode it like this:
when HTTP_RESPONSE {
Check if response is a redirect
if {[HTTP::is_redirect]}{
Rewrite the location header if it matches a hardcoded host value
HTTP::header replace Location [string map -nocase "http://www.example.com https://www.example.com" [HTTP::header value Location]]
}
}
A more general (but less efficient) option would be to save the Host header value on every request and check if the Location header starts with it:
when HTTP_REQUEST {
Save host header in lower case
set host [string tolower [HTTP::host]]
}
when HTTP_RESPONSE {
Check if response is a redirect
if {[HTTP::is_redirect] and [string tolower [HTTP::header value Location]] starts_with "http://$host"}{
Rewrite the location header if it matches a hardcoded host value
HTTP::header replace Location [string map -nocase "http:// https://" [HTTP::header value Location]]
}
}
Aaron
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