Mulitple URL Replace and stream profile

I have a case where the internal naming of multiple servers have to be replaced by a single FQDN. I am succesful when dealing with one instance but not with many. Here is my current iRule, note: it seems to never hit on the second object.

when HTTP_RESPONSE {

if { [HTTP::is_redirect]} {

HTTP::header replace Location “[string map -nocase [list inside1.net fqdn.com] [HTTP::header value Location]]”

} else {

HTTP::header replace Location “[string map -nocase [list inside2.net fqdn.com] [HTTP::header value Location]]”}

}

Also; I have a stream profile applied to the VIP:

Source is blank.

Target: @inside1.net@fqdn.com@ @inside2.net@fqdn.com@

Any help would be much appreciated!

Can you try this please? I’ve added some spaces (which probably won’t help) and some logging that might;

when HTTP_RESPONSE {
 if { [HTTP::is_redirect] } {
  HTTP::header replace Location "[string map -nocase [list inside1.net fqdn.com] [HTTP::header value Location]]" }
 else {
  log local0. "Changing inside2.net location header"
  HTTP::header replace Location "[string map -nocase [list inside2.net fqdn.com] [HTTP::header value Location]]" }
}

Thanks. Tried it and again it only works for the first item, in this case it replaced inside1.net to fqdn.com but it always seems to fail on the following item(s) no matter the order.

Jan 14 15:35:43 tmm tmm[5009]: Rule Test-Else : Changing inside2.net location header

Jan 14 15:35:43 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Changing inside2.net location header

Jan 14 15:35:43 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Changing inside2.net location header

Jan 14 15:35:44 tmm tmm[5009]: Rule Test-Else : Changing inside2.net location header

Jan 14 15:35:44 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Changing inside2.net location header

Jan 14 15:35:44 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Changing inside2.net location header

Jan 14 15:35:45 tmm tmm[5009]: Rule Test-Else : Changing inside2.net location header

OK, so how about we make it real simple;

when HTTP_RESPONSE {
 if { [HTTP::is_redirect] } {
  HTTP::header replace Location "fqdn.com" }
 else {
  log local0. "Changing inside2.net location header"
  HTTP::header replace Location "fqdn.com" }
}

Btw, is the Stream profile working OK?

e.g.

[root@ve10:Active] config  b virtual bar80 list
virtual bar80 {
   snat automap
   pool foo
   destination 172.28.19.252:80
   ip protocol 6
   rules myrule
   profiles {
      http {}
      tcp {}
   }
}
[root@ve10:Active] config  b pool foo list
pool foo {
   members 200.200.200.101:80 {}
}
[root@ve10:Active] config  b rule myrule list
rule myrule {
   when HTTP_RESPONSE {
  if { [HTTP::is_redirect]} {
    HTTP::header replace Location "[string map -nocase [list inside1.net fqdn.com inside2.net fqdn.com] [HTTP::header value Location]]"
  }
}
}

 original response

[root@ve10:Active] config  curl -I http://200.200.200.101/something1
HTTP/1.1 302 Found
Date: Tue, 15 Jan 2013 04:17:33 GMT
Server: Apache/2.2.3 (CentOS)
Location: http://inside1.net/somethingone
Content-Type: text/html; charset=iso-8859-1

[root@ve10:Active] config  curl -I http://200.200.200.101/something2
HTTP/1.1 302 Found
Date: Tue, 15 Jan 2013 04:17:34 GMT
Server: Apache/2.2.3 (CentOS)
Location: http://inside2.net/somethingtwo
Content-Type: text/html; charset=iso-8859-1

 response through bigip

[root@ve10:Active] config  curl -I http://172.28.19.252/something1
HTTP/1.1 302 Found
Date: Tue, 15 Jan 2013 04:19:27 GMT
Server: Apache/2.2.3 (CentOS)
Location: http://fqdn.com/somethingone
Content-Type: text/html; charset=iso-8859-1

[root@ve10:Active] config  curl -I http://172.28.19.252/something2
HTTP/1.1 302 Found
Date: Tue, 15 Jan 2013 04:19:28 GMT
Server: Apache/2.2.3 (CentOS)
Location: http://fqdn.com/somethingtwo
Content-Type: text/html; charset=iso-8859-1

Thanks - but unfortunately neither of these suggestions worked. The following was really close but didn’t quite like the directories.

when HTTP_RESPONSE {

if { [HTTP::is_redirect] } {

HTTP::header replace Location “fqdn.com” }

else {

log local0. “Changing inside2.net location header”

HTTP::header replace Location “fqdn.com” }

}

but unfortunately neither of these suggestions worked. hmm… would you mind showing us what is not working?

When using the following iRule:

when HTTP_RESPONSE {

if { [HTTP::is_redirect] } {

HTTP::header replace Location “fqdn.com” }

else {

log local0. “Changing inside2.net location header”

HTTP::header replace Location “fqdn.com” }

}

Trying to render either inside1.net or inside2.net the following error(s) occur…

java.io.FileNotFoundException: /content/players/fqdn.com

You’re replacing the Location header with just fqdn.com. The browser assumes that means it should make a new GET request to it’s current host/URL + fqdn.com. If they’d requested http://www.example.com/path, they’d make a new request to http://www.example.com/path/fqdn.com which isn’t what you want.

Can you try Nitass’s suggestion and reply back with what you find?

HTTP::header replace Location “[string map -nocase [list inside1.net fqdn.com inside2.net fqdn.com] [HTTP::header value Location]]”

If this doesn’t work, can you log the new location header value and describe what request the client makes and the server’s response?

log local0. “New Location: [HTTP::header replace Location]”

Aaron

So this irule is very very close…

when HTTP_RESPONSE {

if { [HTTP::is_redirect] } {

HTTP::header replace Location “fqdn.com” }

else {

log local0. “Changing inside2.net location header”

HTTP::header replace Location “fqdn.com” }

}

But the header replace is almost doing to much… see the URL below following the replace. The trailing portion after “/players/” is being rewritten as well…

fqdn.com - This website is for sale! - fqdn Resources and Information.**

This is what it should be…

fqdn.com - This website is for sale! - fqdn Resources and Information.

In wireshark this is what we see happening…

[truncated] GET fqdn.com - This website is for sale! - fqdn Resources and Information.

[truncated] GET fqdn.com - This website is for sale! - fqdn Resources and Information.

GET fqdn.com - This website is for sale! - fqdn Resources and Information. HTTP/1.1\r\n - PROBLEM

So here’s a quick update…

For clarity, I need:

inside1.net to be replaced by fqdn.com

inside2.net to be replaced by fqdn.com

inside3.net to be replaced by fqdn.com

etc..

This irule (below) is successful but for whatever reason I can only get it to do one header replace at a time, rather then several, which is the objective.

when HTTP_RESPONSE {

log local1. “=============================================”

log local1. “$LogString (response) - status: [HTTP::status]”

foreach aHeader [HTTP::header names] {

log local1. “$aHeader: [HTTP::header value $aHeader]”

}

log local1. “=============================================”

if { [HTTP::is_redirect] } {

HTTP::header replace Location “[string map -nocase [list http%3A%2F%2Finside2.net http%3A%2F%2Ffqdn.com] [HTTP::header value Location]]”

See logs (successful)

Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : =============================================

Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : Cookie: JSESSIONID=EE9C8FB6F1E9DB6B9A3E3CDB08446EC0

Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : Pragma: no-cache

Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : X-Xorwarded-For: 00.000.000.000

Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : Cache-Control: no-cache, max-age=259200

Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : Connection: close

Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : =============================================

Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : =============================================

Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : =============================================

Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Client 121.122.122.122%6:31772 → fqdn.com - This website is for sale! - fqdn Resources and Information._launch/redirector?url=http%3A//inside2.net%3A80/Saba/AICCReporter%3FscormSessionKey%3DEE9C8FB6F1E9DB6B9A3E3CDB08446EC0%26sitename%3DSabaSite%26lms_data%3D%25253BconformanceLevel%25253D0%26cmi_entry%3Daireg000000000006535aises000000000002167&debug=false (response) - status: 200

Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Date: Thu, 17 Jan 2013 14:53:27 GMT

Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Server: Microsoft-IIS/6.0

Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : X-Powered-By: Servlet 2.4; JBoss-4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)/Tomcat-5.5

Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : X-Powered-By: Servlet 2.4; JBoss-4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)/Tomcat-5.5

Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Connection: close

Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Content-Type: text/plain

Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : =============================================

Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : =============================================

Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Client 121.122.122.122%6:31772 → fqdn.com - This website is for sale! - fqdn Resources and Information._launch/redirector?url=http%3A//inside2.net%3A80/Saba/AICCReporter%3FscormSessionKey%3DEE9C8FB6F1E9DB6B9A3E3CDB08446EC0%26sitename%3DSabaSite%26lms_data%3D%25253BconformanceLevel%25253D0%26cmi_entry%3Daireg000000000006535aises000000000002167&debug=false (response) - status: 200

Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Date: Thu, 17 Jan 2013 14:53:27 GMT

Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Server: Microsoft-IIS/6.0

Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : X-Powered-By: Servlet 2.4; JBoss-4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)/Tomcat-5.5

Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : X-Powered-By: Servlet 2.4; JBoss-4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)/Tomcat-5.5

Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Connection: close

Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : Client 121.122.122.122%6:31772 → fqdn.com - This website is for sale! - fqdn Resources and Information._launch/redirector?url=http%3A//inside2.net%3A80/Saba/AICCReporter%3FscormSessionKey%3DEE9C8FB6F1E9DB6B9A3E3CDB08446EC0%26sitename%3DSabaSite%26lms_data%3D%25253BconformanceLevel%25253D0%26cmi_entry%3Daireg000000000006535aises000000000002167&debug=false (response) - status: 200

Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : Date: Thu, 17 Jan 2013 14:53:27 GMT

Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : Server: Microsoft-IIS/6.0

Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : X-Powered-By: Servlet 2.4; JBoss-4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)/Tomcat-5.5

Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : X-Powered-By: Servlet 2.4; JBoss-4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA date=200710221139)/Tomcat-5.5

Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : Connection: close

Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : Content-Type: text/plain

Jan 17 09:49:28 tmm tmm[5009]: Rule Test-Else : =============================================

Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Content-Type: text/plain

Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : =============================================

This irule (below) is successful but for whatever reason I can only get it to do one header replace at a time, rather then several, which is the objective. what does “one header replace at a time” mean? are you referring to inside2.net in query string below which is not replaced with fqdn.com?

Jan 17 09:49:28 172.16.10.88 local/tmm info tmm[5009]: Rule Test-Else : Client 121.122.122.122%6:31772 → fqdn.com - This website is for sale! - fqdn Resources and Information._launch/redirector?url=http%3A//inside2.net%3A80/Saba/AICCReporter%3FscormSessionKey%3DEE9C8FB6F1E9DB6B9A3E3CDB08446EC0%26sitename%3DSabaSite%26lms_data%3D%25253BconformanceLevel%25253D0%26cmi_entry%3Daireg000000000006535aises000000000002167&debug=false (response) - status: 200

Sorry - I meant that when I try the iRule with an ‘Else’ statement (as seen a the top of this thread) the replace funtion only triggers on the first variable. In the recent example (directly above) I removed the else statement, which allows for the replace to happen but again I’m limited to a single replace funtion. In that case I was replacing inside2.net to FQDN.com.

Just not sure why the ELSE statement is breaking.

again I’m limited to a single replace funtion. In that case I was replacing inside2.net to FQDN.com.doesn’t adding domain into the list work?

e.g.

HTTP::header replace Location “[string map -nocase [list http%3A%2F%2Finside1.net http%3A%2F%2Ffqdn.com http%3A%2F%2Finside2.net http%3A%2F%2Ffqdn.com http%3A%2F%2Finside3.net http%3A%2F%2Ffqdn.com] [HTTP::header value Location]]”

Thanks!

I’m getting closer… now inside2.net works as required. As for inside1.net it no longer gives me a broken URL error, but the page renders as blank. Any ideas?

when HTTP_REQUEST {

set LogString “Client [IP::client_addr]:[TCP::client_port] → [HTTP::host][HTTP::uri]”

log local1. “=============================================”

log local1. “$LogString (request)”

foreach aHeader [HTTP::header names] {

log local1. “$aHeader: [HTTP::header value $aHeader]”

}

log local1. “=============================================”

}

when HTTP_RESPONSE {

log local1. “=============================================”

log local1. “$LogString (response) - status: [HTTP::status]”

foreach aHeader [HTTP::header names] {

log local1. “$aHeader: [HTTP::header value $aHeader]”

}

log local1. “=============================================”

if { [HTTP::is_redirect] } {

HTTP::header replace Location “[string map -nocase [list http%3A%2F%2Finside1.net http%3A%2F%2Ffqdn.com http%3A%2F%2Finside2.net http%3A%2F%2Ffqdn.com] [HTTP::header value Location]]”

but the page renders as blank. Any ideas? can you run tcpdump to see where the wrong is?

e.g.

tcpdump -nni 0.0:nnn -s0 -w /var/tmp/output.pcap host x.x.x.x or host y.y.y.y or host z.z.z.z

x.x.x.x is virtual server ip address

y.y.y.y and z.z.z.z are pool member ip addresses

Oddly enough, I’m seeing a “http/1.1 500 Internal Server Error\r\n” at the bottom of the TCP stream. When I dig deeper I see the following: java.net.UnknownHostException: fqdn.com

\r\n

Basically my understanding of this is that the application (server level) can not resolve fqdn.com. Almost like I need a reverse rewrite or something as well??

Fixed. The URL for inside2.net had a launcher that included an embedded redirect which happened to contain inside1.net, which was being rewritten to fqdn.com in the irule, but in this case we needed the redirect to remain unchanged. Simple change to the servers host file to trick it and we’re in business.

Thanks for all the help, appreciate it!