Forum Discussion
Leslie_South_55
Nov 06, 2008Nimbostratus
HTTP::respond + append URI from HTTP::request
I am using the sample for HTTP::respond 301 from http://devcentral.f5.com/Wiki/default.aspx/iRules/findclass.html
I need to be able to grab anything after the host and append this to the 3rd row in my classfile
So if the request was for
http://host1.domain.com/foo
and my class file has this
"host1.domain.com 302 https://securehost.domain.com"
I want to send
https://securehost.domain.com/foo
to the client. The data after / in the request could be anything and everything, including multiple directories..a request for http://host1.domain.com/foo/bar/foobar/ would need to go to https://securhost.domain.com/foo/bar/foobar/
Thanks,
-L
- Alok_3817NimbostratusHi lsouth,
when HTTP_REQUEST { if {[HTTP::host] equals "host1.domain.com" } { HTTP::redirect https://securehost.domain.com[HTTP::uri] } }
- Leslie_South_55NimbostratusThe 301 vs. a 302 is the request of the client, and to my understanding, HTTP::respond is the only way to issue a 301. Using the example I can append anything to the URI, but I get a double slash in the request
when HTTP_REQUEST { Check if there is a class entry which starts with the requested URI set row [findclass [string tolower [HTTP::host]] $::host_redirects] Check if there was a matched row if { $row ne "" }{ log local0. "Matched $row" Send a response using the status and location from the class HTTP::respond [getfield $row " " 2] Location [getfield $row " " 3][HTTP::uri] Connection Close Clear the row variable unset row } }
- Leslie_South_55NimbostratusUPDATE
- hooleylistCirrostratusIf the third field in the class don't have a trailing slash, then you shouldn't see a double slash in the redirect unless the requested URI had two slashes
- Alok_3817NimbostratusOh great,
- hooleylistCirrostratusA 301 response is used for permanent redirects:
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