Forum Discussion
Irule Vs rewrite - FQDN hostname
Below is what I have in 1 irule. Fails because the backend server is expecting---https://ServerName.Domain.com:8443/etc/bc/ui5_ui5/ui2/ushell/shells/abap/something.html"
But I want the client browser to have the below once the server completes its jobs post request.
https://FQDN/etc/bc/ui5_ui5/ui2/ushell/shells/abap/something.html
Hope this makes sense.
when HTTP_REQUEST {
# Check if requested host doesn't start with www.example.com
if {not ([string tolower [HTTP::host]] starts_with "https://FQDN/")}{
# Replace the host header value with newhost.example.com
HTTP::header replace Host "https://ServerName.Domain.com:8443/"
if { [HTTP::uri] starts_with "/" } {
set uri [string map -nocase {"/" "/etc/bc/ui5_ui5/ui2/ushell/shells/abap/something.html"} [HTTP::uri]]
HTTP::uri $uri
}
}
}
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
}
}
- Mr__TFeb 23, 2023
Cirrus
Thanks for the clarifications Amine_Kadimi.
Let me try this and report back.
- Mr__TFeb 23, 2023
Cirrus
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.
Thanks again.
- Amine_KadimiFeb 23, 2023
MVP
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)
- Mr__TFeb 23, 2023
Cirrus
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.
You are appreciated.
- Mr__TMar 15, 2023
Cirrus
Hi Amine_Kadimi,
This is what I have from your suggestion. The replace host does not seem to execute. redirection does happen.
when HTTP_REQUEST {
if { [HTTP::uri] equals "/"}
{
HTTP::redirect "https://Servername:8443/etc/bc/ui5_ui5/ui2/ushell/shells/abap/page.html"
}
else {
HTTP::header replace Host FQDN
}
}
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