Clients will type appname.domain.com, I need to redirect to another URL (working via IRule) that the server understands but keep the friendly name appname.domain.com in the browser post every response. Protocol is https already E3E. T
@Mr_T So a few things stand out to me. First is that you don’t want a redirect you would like a rewrite but in your rewrite it looks like you want to add on a port at the end of the host which shouldn’t be necessary because your pool member should be listening on that port already. The last is whenever they hit just “/” as the URI do you want to redirect them to a specific path? So as an example of how I believe this works.
HTTP::redirect will effectively redirect the client to the new location, and will change the url in the browser. What you need is to replace the host header in the pool side of the connection as described herehttps://clouddocs.f5.com/api/irules/HTTP__host.html
when HTTP_REQUEST {
# Check if requested host doesn't start with www.example.com
if {not ([string tolower [HTTP::host]] starts_with "www.example.com")}{
# Replace the host header value with newhost.example.com
HTTP::header replace Host "newhost.example.com"
}
}
The long URL is what the app has hardcoded and will only respond to that URL. So my goal was to make sure the client only sees the frienly name after the redirects happen. I tried rewrite policies but the IRule seems to be the way to go. The redirect to he long URL works fine, but they dont want to see the servername rather FQDN.
You don’t need to specify https nor the port on the host header, cause those are specified elsewhere, https is by using a ssl servers profile and the port is at the pool member.
Alsop testing if uri starts with / is useless since all uris stars with /.
If I understand correctly your requirement, why not first redirecting user to target path, then doing just the host replacement.
Something like this that :
when HTTP_REQUEST {
if { [HTTP::uri] equals "/"}
{
HTTP::redirect "https://[HTTP::host]/your/full/path/something.html"
}
else {
HTTP::header replace Host ServerName.Domain.com
}
}
I want to make sure I communicate the issue properly. The redirect covers the URL change in the request.The hostheader replace needs to happen on the response from the server back to the client keeping the existing uri from the redirect.
There is no host header in the responses since it is a request header in http. So as long as you connect to the right ip and port of the backend server, and you have the correct host header in the request from F5 (since you handled that with the replace header command), you should get the answer from the server. This answer will then be sent to to the client from F5, and this should be transparent for the client unless you have some redirection happening in the server itself thats is redirecting to the real server name because F5 by default is forwarding these kind of redirections to the client. This can be checked on the client using F12 developer tools. If that is the case, there is solution for that (redirect rewrite)
Bingo! @Amine_Kadimi . There is some redirects happening on the server after the redirect of the request to the URL which includes port https://ServerName:8443/long uri.(port must be specified since not default protocol port) I have tried the redirect rewrite but i am a newbie to these features.
@Mr_T If your pools have multiple pool members I do not believe this will be possible because you will require mapping a single FQDN to multiple server names depending on the pool member that you are sent to. Your best bet here would be to work with the server/app admins to see if they have a way of changing what they expect for the host and path. Typically all of this can be done at the server level instead of performing a bandaid at the F5 which in some cases such as yours will not work because of the single FQDN to many names issue.
@Mr_T The following is the base iRule and you can continue to add on additional “elseif” to this to account for additional applications and change the port “8080” to the respective port.
when HTTP_REQUEST priority 500 {
if {[string tolower [HTTP::host]] == "example.com"} {
HTTP::host [string map {"example.com" "servername.example.com:8080"}[HTTP::host]]
}
}