Forum Discussion
Rogerio_Teixeir
Nimbostratus
Apr 10, 2008Replace host based on file type
Hi,
Im trying to creat a irule that replace de hostname (FQDN) based on what fily type is request...
Like this:
Based on class images (jpg,gif,png...etc)
client request for :www.foobar.com/img/nonono.jpg
replace the hostname
Server respond: images.foobar.com/img/nonono.jpg
???
Regards,
Rogerio
- Chris_Seymour_1Historic F5 AccountRogerio,
when HTTP_REQUEST { if { [HTTP::path] ends_with ".jpg" } { HTTP::redirect "http://images.foobar.com[HTTP::uri]" } }
class images { ".bmp" ".gif" ".jpg" ".pdf" ".BMP" ".GIF" ".JPG" ".PDF" } when HTTP_REQUEST { if { [matchclass [HTTP::path] ends_with $::images] } { HTTP::redirect "http://images.foobar.com[HTTP::uri]" } }
- Rogerio_Teixeir
Nimbostratus
Hi, - Rogerio_Teixeir
Nimbostratus
Hi, - hoolio
Cirrostratus
Hi Rogerio,when HTTP_RESPONSE { Check if the Content-Type header value matches our criteria if {[HTTP::header value Content-Type] contains "somestring"}{ log local0. "[IP::client_addr]:[TCP::client_port]: Matched the Content-Type check for [HTTP::header value Content-Type]" Initialize a variable to save the cookies set cookie_string "" Loop through each Set-Cookie header. Save the value to a string, and remove the header. while {[HTTP::header exists Set-Cookie]}{ Append the current Set-Cookie value to the cookie string append cookie_string [HTTP::header value Set-Cookie]\; log local0. "[IP::client_addr]:[TCP::client_port]: Current \$cookie_string: $cookie_string" Delete the current Set-Cookie header HTTP::header remove Set-Cookie } Include the cookies in the 302 response if there were any if {[string length $cookie_string]}{ log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting with cookies to: http://example.com Set-Cookie $cookie_string" Send the 302 redirect response with the cookies HTTP::respond 302 Location "http://example.com" Set-Cookie $cookie_string } else { log local0. "[IP::client_addr]:[TCP::client_port]: Redirecting without cookies to: http://example.com" Send the 302 redirect response without the Set-Cookie header as there weren't any cookies HTTP::respond 302 Location "http://example.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