Forum Discussion
Rewrite static content response for CDN network without modifying site code
Hello! I have a delicate problem to which I have not (yet) found a working solution. I would like to test out a CDN network without modifying the site code. So I thought this simple iRule would do it for rewriting /static content location:
when HTTP_RESPONSE { HTTP::collect 1000000 }
when HTTP_RESPONSE_DATA { log "Replacing payload with new data." HTTP::payload replace 0 [HTTP::payload length] [string map { cdn01.site.com/static} [HTTP::payload]] HTTP::release }
Issue is that site use relative URL:s so the host never comes in the payload = no rewrite occur.
Also tested creating a stream profile and added it to VIP to replace https://www.site.com/static with https://cdn01.site.com/static but it din't work. Any idea how to do this?
Kind regards, Orjan
- Jeff_Maddox_394Historic F5 Account
You could try doing redirects for all requests other than the initial page.
something like: when HTTP_REQUEST { if { uri not equal /} { redirect http::cdn01.site.com/...uri }
}
- RasmanNimbostratus
Thanks! That works. I would like to avoid redirects but if there's no other way this might do:
when HTTP_REQUEST { if { [HTTP::uri] starts_with "/static"} { HTTP::redirect https://cdn01.site.com[HTTP::uri] } }
Regards, Orjan
- Jeff_Maddox_394Historic F5 Account
Yea, the only other way i see is to know all of your relative urls, and do a Stream method to insert the https::host before each one in your response. you would have to do it statically for each one.
Recent Discussions
Related Content
* 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