Hello Guys/Gals -- I’m new to irules and am trying to figure out a re-write scenario, I’m trying to change a current rule that does a redirect, and change it to rewrite. The current rule is like this, it works but of course the browser url gets updated and we want to keep the destination from displaying.
=================================================================================================== when HTTP_REQUEST { if { [string tolower [HTTP::host]] starts_with “abc-news.east.foo.com” } { HTTP::redirect “https://server.nbc-news.west.foo.com:7012/Portal/index.html” } } ===================================================================================================
I Attempted the following re-writes but browser hangs. I’m trying to forward to a specific domain and server that is listening on a specific port.
Wondering if I might need to use a pool member to redirect, so I created a pool that has it service port going to 7012. It appears to be listening OK as it green. So my question is how can I rewrite to go to that pool or am I going about this the wring way. I’m not finding much about rewrite using a port.
I don’t think you need to do anything with the URI and the host doesn’t need the https:// in it. I don’t think you need the 7012 in the header either. You’re pool members can be listening on any port you want as long as you configure LTM appropriately.
Keep in mind that absolute links (if any) in responses will contain the ‘original’ hostname.’
You shouldn’t need to specify the port unless the application requires it. It’s rare but some do. So instead of redirecting on host, you want to silently modify the host header for ingress traffic. You’ll definitely need a pool with port 7012 members and modify the host header on every request. The URI change from “/” to “/Portal/index.html” should probably be a redirect though - unless you want to be in the business of managing every possible URI (the work of a rewrite proxy).
Again, should you need to completely hide the URI as well, you can use the HTTP::uri command on the ingress, but you have to be mindful of any possible URI translations.
Note, as shown in the examples by tvotta and nitass you should remove the quotes around Host. Also, please check there is a space before and after each } or {. You also need to remove the ( and ).
It doesn’t matter what port the server is listening on, LTM is acting as a proxy so your Virtual Server can be on port 443 and your pool member listening on 7012 and it all just works; the client connection is terminated on 443 and a new connection is created from the F5 to the pool member on 7012. No need to use an iRule to change the port, it’s automatic. You could have six pool members all listening on different Service Ports and it wouldn’t matter, it would work.
This is an existing IP that resolves as abc-news.east.foo.com. This is set up as a VS and the current working irule is associated to it, but no pool are associated with this.
2. modify abc-news.east.foo.com virtual server similar to the following configuration
[root@ve10:Active] config b virtual bar list
virtual bar {
snat automap
pool foo
destination 172.28.19.79:443
ip protocol 6
rules myrule
profiles {
clientssl {
clientside
}
http {}
serverssl {
serverside
}
tcp {}
}
}
[root@ve10:Active] config b pool foo list
pool foo {
members 200.200.200.101:7012 {}
}
[root@ve10:Active] config b rule myrule list
rule myrule {
when HTTP_REQUEST {
if {[HTTP::uri] equals "/"} {
HTTP::uri "/Portal/index.html"
}
HTTP::header replace Host "server.nbc-news.west.foo.com:7012"
}
}
log local0. “host header after header replace = [HTTP::header Host]” after the HTTP:: header replace, but unfortunately still the header is not getting rewritten.
Oct 2 17:20:48 local/tmm3 info tmm3[5303]: Rule portral-dev : changing uri to /Portal/index.html
Oct 2 17:20:48 local/tmm3 info tmm3[5303]: Rule portral-dev : incoming host header = abc-news.east.foo.com
Oct 2 17:20:48 local/tmm3 info tmm3[5303]: Rule portral-dev : host header after header replace = abc-news.east.foo.com
Oct 2 17:20:49 local/tmm info tmm[5299]: Rule portral-dev : incoming host header = abc-news.east.foo.com
Oct 2 17:20:49 local/tmm info tmm[5299]: Rule portral-dev : host header after header replace = abc-news.east.foo.com
Oct 2 17:20:49 local/tmm3 info tmm3[5303]: Rule portral-dev : incoming host header = abc-news.east.foo.com
Oct 2 17:20:49 local/tmm3 info tmm3[5303]: Rule portral-dev : host header after header replace = abc-news.east.foo.com
Oct 2 17:20:49 local/tmm2 info tmm2[5302]: Rule portral-dev : incoming host header = abc-news.east.foo.com
Oct 2 17:20:49 local/tmm2 info tmm2[5302]: Rule portral-dev : host header after header replace = abc-news.east.foo.com
Must be another method to get this header to re-write.
Can you try this with additional debug logging? I assume you’re on a pre-v11.0 release which had caching of many of the HTTP:: command values in the same iRule event.
when HTTP_REQUEST {
log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::method] to [HTTP::host][HTTP::uri]"
if { [HTTP::uri] equals "/" } {
log local0. "[IP::client_addr]:[TCP::client_port]: Rewriting / to /Portal/index.html"
HTTP::uri "/Portal/index.html"
}
HTTP::header replace Host "server.nbc-news.west.foo.com:7012"
}
when HTTP_REQUEST priority 501 {
Debug logging only--remove or comment out this event once testing is complete
log local0. "[IP::client_addr]:[TCP::client_port]: Updated host/uri: [HTTP::host][HTTP::uri]
}
when HTTP_RESPONSE {
log local0. "[IP::client_addr]:[TCP::client_port]: [HTTP::status] response from [LB::server]. Redirect location: [HTTP::header location]"
}