Forum Discussion
URI and Header Host file replace
I am having a hard time trying to figure out Irule to do the following.
If a user hits https://whateverwebsite.com/static/test.html or /static/test/test.html. etch
I want that to get redirected to another domain but it no do a 302 it just rewrites the response. Now I have figured out how to the the hostname but I can never get it to work with the URI. Also i basically only want it to do it just for the that one URI and nothing else. Also if a user types anything after that URI i want it to redirect that.
So
whatever.com goes to my F5 poolwhateever.com/static "anything behind that" gets header rewrite without a 302.
This is what I have used for the Host and it seems to work, just configure out the URI.
when HTTP_REQUEST { Remove the Accept-Encoding header from requests so that the server does not compress responses HTTP::header remove Accept-Encoding
Disable the STREAM profile for request traffic
STREAM::disable
replace the Host header
if { [HTTP::uri] starts_with "/static" } { HTTP::header replace Host "whaterver.com"} } when HTTP_RESPONSE { Look for and replace redirects from the server if { [HTTP::header exists Location] } { HTTP::respond 200 HTTP::header replace Location [string map {"whaterver.com" "newwhaterver.com"} [HTTP::header Location]] }
For any text-based response enable a STREAM mapping to replace specific values
To use this, enable an empty STREAM profile to the virtual server
if { [HTTP::header Content-Type] contains "text" } {
STREAM::expression {@whaterver.com@newwhaterver.com@}
STREAM::enable
}
}
6 Replies
- nitass
Employee
Now I have figured out how to the the hostname but I can never get it to work with the URI.
do you mean to rewrite uri? if yes, you can use HTTP::uri command.
HTTP::uri
https://devcentral.f5.com/wiki/iRules.HTTP__uri.ashx - RoyDShaw_195277
Nimbostratus
I want the URI to stay the same, just want the hostname to change. But I only want the hostname to change if that URI is present.
So if a user goes to oldsite.com\static\whatever
F5 responds with
newsite.com\static\whaterver
- nitass
Employee
isn't it what HTTP::header replace in your irule does? HTTP::header replace Host "whaterver.com"
- RoyDShaw_195277
Nimbostratus
Yes and if I just put in whatever.com it actually works. I see it return with a 200 and the new hostname. It just anytime I add the \static URI at the end it does not work.
- nitass
Employee
uri (e.g. /static) is not part of host header.
- RoyDShaw_195277
Nimbostratus
Yeah, I am trying to figure out how to make the host header change when that URI comes up.
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)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