Can't get my redirect to work !!!

Hi All,

I’m trying to get my redirect to work and I’m have some problems, can some one put me right please.

when HTTP_REQUEST {

if { [HTTP::uri] equals "https://test.geowessex.com" } {
HTTP::redirect "https://test.geowessex.com/geoserver/"}
elseif { [HTTP::uri] equals "https://test2.geowessex.com" } {
HTTP::redirect "https://vmcrgifme1"}

}

Hi Paul!

You’re comparing against the full url whereas the uri is the part after the host.

Try this:

when HTTP_REQUEST {

    set host [string tolower [HTTP::host]]

    if { $host equals "test.geowessex.com" } {
        HTTP::redirect "https://test.geowessex.com/geoserver/"}
    elseif { $host equals "test2.geowessex.com" } {
        HTTP::redirect "https://vmcrgifme1"
    }

}

Hope that answers your question. :slightly_smiling_face:

/Patrik

Hi Patrik,

Just to give you some background, this irule is for a F5 ASM box. This irule does not work at all, before I had an irule that worked fine (see below)

when HTTP_REQUEST { if { [HTTP::host] equals “https://test.geowessex.com” } { HTTP::redirect “https://test.geowessex.com/geoserver/”} }

but with your irule I can’t get it to work at all.

I hope you can help.

Hi Paul

Strange.

Try this rule instead?

when HTTP_REQUEST {

    set host [string tolower [HTTP::host]]

    if { $host equals "https://test.geowessex.com" } {
        HTTP::redirect "https://test.geowessex.com/geoserver/"}
    elseif { $host equals "https://test2.geowessex.com" } {
        HTTP::redirect "https://vmcrgifme1"
    }
}

If that does not work, try adding log section to see what the hosts header contains.

when HTTP_REQUEST {

    set host [string tolower [HTTP::host]]
    log local0. $host
    if { $host equals "https://test.geowessex.com" } {
        HTTP::redirect "https://test.geowessex.com/geoserver/"}
    elseif { $host equals "https://test2.geowessex.com" } {
        HTTP::redirect "https://vmcrgifme1"
    }
}

Then check the result in the /var/log/ltm log.

/Patrik

Hi Patrik,

The first redirect works (https://test.geowessex.com) but it ever does the second one https://test2.geowessex.com, I don’t no what is going wrong ?

Tue Jun 24 12:34:29 BST 2014 info asm1 tmm[11765] Rule /Common/New-Geowessex-Redirect : test.geowessex.com Tue Jun 24 12:34:29 BST 2014 info asm1 tmm1[11765] Rule /Common/New-Geowessex-Redirect : test.geowessex.com Tue Jun 24 12:34:30 BST 2014 info asm1 tmm[11765] Rule /Common/New-Geowessex-Redirect : test.geowessex.com Tue Jun 24 12:34:30 BST 2014 info asm1 tmm[11765] Rule /Common/New-Geowessex-Redirect : test.geowessex.com Tue Jun 24 12:34:30 BST 2014 info asm1 tmm1[11765] Rule /Common/New-Geowessex-Redirect : test.geowessex.com Tue Jun 24 12:34:30 BST 2014 info asm1 tmm[11765] Rule /Common/New-Geowessex-Redirect : test.geowessex.com Tue Jun 24 12:34:30 BST 2014 info asm1 tmm1[11765] Rule /Common/New-Geowessex-Redirect : test.geowessex.com

Hi Paul!

Tue Jun 24 12:34:29 BST 2014 info asm1 tmm[11765] Rule /Common/New-Geowessex-Redirect : test.geowessex.com
Tue Jun 24 12:34:29 BST 2014 info asm1 tmm1[11765] Rule /Common/New-Geowessex-Redirect : test.geowessex.com 
Tue Jun 24 12:34:30 BST 2014 info asm1 tmm[11765] Rule /Common/New-Geowessex-Redirect : test.geowessex.com 
Tue Jun 24 12:34:30 BST 2014 info asm1 tmm[11765] Rule /Common/New-Geowessex-Redirect : test.geowessex.com 
Tue Jun 24 12:34:30 BST 2014 info asm1 tmm1[11765] Rule /Common/New-Geowessex-Redirect : test.geowessex.com 
Tue Jun 24 12:34:30 BST 2014 info asm1 tmm[11765] Rule /Common/New-Geowessex-Redirect : test.geowessex.com 
Tue Jun 24 12:34:30 BST 2014 info asm1 tmm1[11765] Rule /Common/New-Geowessex-Redirect : test.geowessex.com

Looking at your log you never use test2.geowessex.com and that’s why the second redirect never fires.

/Patrik

Hi Patrik,

But I was ? so i’m even more confused

Maybe you don’t reach the LTM when using test2.geowessex.com? Check the dns and the hosts file on your client?

/Patrik

Hi Patrik,

I can see what is happening now, ASM does not seem to be hitting the irule at all. I need to take off the security policy next and see weather that make a difference.

Sounds like a plan! :slight_smile:

@Patrik: You’ve re-introduced the protocol (https) in the comparison. However, HTTP::host contains the host only.

when HTTP_REQUEST {

    set host [string tolower [HTTP::host]]

    if { $host equals "test.geowessex.com" } {
    HTTP::redirect "https://test.geowessex.com/geoserver/"}
    elseif { $host equals "test2.geowessex.com" } {
        HTTP::redirect "https://vmcrgifme1"
    }
}

Hi Patrik,

I removed the security policy and it made no difference, So I know it’s not the ASM part given me the problem. Looking at the irule I had in place at the start, this also did not work at closer inspection. So I’m back to needing an irule that can do both the redirects, I hope you can help Patrik or any one else out there.

Many Thanks

Paul

Hi Paul!

Yeah, the initial hosts was a bit strange to begin with and we would have had to fix them with some string manipulations later on anyway in order for normal requests to pass as well.

Let’s start with reverting to my original suggestion:

when HTTP_REQUEST {

    set host [string tolower [HTTP::host]]

    log local0. $host

    if { $host equals "test.geowessex.com" } {
        log local0. "Redirected based on $host"
        HTTP::redirect "https://test.geowessex.com/geoserver/"}
    elseif { $host equals "test2.geowessex.com" } {
        log local0. "Redirected based on $host"
        HTTP::redirect "https://vmcrgifme1"
    }

}

This rule would require you to hit the VS with either test.geowessex.com or test2.geowessex.com in order to trigger.

Then let’s see if you hit the VS when using both of them. Login to the LTM over SSH and run the following command:

tcpdump -nni any host [virtual server ip] and host [your client ip]

Then browse to both domains and make sure that a full handshake is established and data is being sent in both cases.

Please let me know the outcome.

/Patrik

Hi Patrik,

The redirect still not working, tcpdump below;

[root@asm1:Active:Standalone] config tcpdump -nni any host 195.49.180.208 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on any, link-type EN10MB (Ethernet), capture size 96 bytes 07:51:46.449816 arp who-has 195.49.180.208 tell 195.49.180.193 07:51:46.449832 arp reply 195.49.180.208 is-at 00:01:d7:d9:41:83 07:51:46.449957 IP 172.23.101.211.59931 > 195.49.180.208.443: S 4045951861:4045951861(0) win 8192 07:51:46.449987 IP 195.49.180.208.443 > 172.23.101.211.59931: S 945986584:945986584(0) ack 4045951862 win 4380 07:51:46.450298 IP 172.23.101.211.59931 > 195.49.180.208.443: . ack 1 win 64240 07:51:46.449960 IP 172.23.101.211.59932 > 195.49.180.208.443: S 427388285:427388285(0) win 8192 07:51:46.449993 IP 195.49.180.208.443 > 172.23.101.211.59932: S 713890173:713890173(0) ack 427388286 win 4380 07:51:46.450388 IP 172.23.101.211.59932 > 195.49.180.208.443: . ack 1 win 64240 07:51:46.450920 IP 172.23.101.211.59931 > 195.49.180.208.443: P 1:170(169) ack 1 win 64240 07:51:46.450944 IP 195.49.180.208.443 > 172.23.101.211.59931: P 1:1369(1368) ack 170 win 4380 07:51:46.451341 IP 172.23.101.211.59931 > 195.49.180.208.443: . ack 1369 win 62872 07:51:46.450901 IP 172.23.101.211.59932 > 195.49.180.208.443: P 1:170(169) ack 1 win 64240 07:51:46.450935 IP 195.49.180.208.443 > 172.23.101.211.59932: P 1:1369(1368) ack 170 win 4380 07:51:46.451333 IP 172.23.101.211.59932 > 195.49.180.208.443: . ack 1369 win 62872 07:51:46.452249 IP 172.23.101.211.59932 > 195.49.180.208.443: P 170:484(314) ack 1369 win 62872 07:51:46.452262 IP 195.49.180.208.443 > 172.23.101.211.59932: . ack 484 win 4863 07:51:46.452592 IP 172.23.101.211.59931 > 195.49.180.208.443: P 170:484(314) ack 1369 win 62872 07:51:46.452602 IP 195.49.180.208.443 > 172.23.101.211.59931: . ack 484 win 4863 07:51:46.455267 IP 195.49.180.208.443 > 172.23.101.211.59932: P 1369:1416(47) ack 484 win 4863 07:51:46.455574 IP 195.49.180.208.443 > 172.23.101.211.59931: P 1369:1416(47) ack 484 win 4863

Please post the ltm log as well. /Patrik

And also you forgot one of the IPs in the tcpdump: Example: tcpdump -nni any host 195.49.180.208 and host 10.10.10.1 /Patrik

Hi Patrik,

Here you go;

[root@asm1:Active:Standalone] config tcpdump -nni any host 195.49.180.253 and host 172.23.101.78 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on any, link-type EN10MB (Ethernet), capture size 96 bytes 08:24:45.077001 IP 195.49.180.253.43746 > 172.23.101.78.8080: S 3716338419:3716338419(0) win 14600 08:24:45.077996 IP 172.23.101.78.8080 > 195.49.180.253.43746: S 3980470878:3980470878(0) ack 3716338420 win 8192 08:24:45.078520 IP 195.49.180.253.43746 > 172.23.101.78.8080: . ack 1 win 115 08:24:45.078805 IP 195.49.180.253.43746 > 172.23.101.78.8080: P 1:134(133) ack 1 win 115 08:24:45.080169 IP 172.23.101.78.8080 > 195.49.180.253.43746: P 1:87(86) ack 134 win 514 08:24:45.080234 IP 172.23.101.78.8080 > 195.49.180.253.43746: P 87:93(6) ack 134 win 514 08:24:45.080236 IP 172.23.101.78.8080 > 195.49.180.253.43746: P 93:130(37) ack 134 win 514 08:24:45.080509 IP 195.49.180.253.43746 > 172.23.101.78.8080: . ack 87 win 115 08:24:45.080512 IP 195.49.180.253.43746 > 172.23.101.78.8080: . ack 93 win 115 08:24:45.080514 IP 195.49.180.253.43746 > 172.23.101.78.8080: . ack 130 win 115 08:24:45.080792 IP 195.49.180.253.43746 > 172.23.101.78.8080: P 134:177(43) ack 130 win 115 08:24:45.080917 IP 195.49.180.253.43746 > 172.23.101.78.8080: P 177:205(28) ack 130 win 115 08:24:45.081303 IP 172.23.101.78.8080 > 195.49.180.253.43746: . ack 205 win 514 08:24:45.082497 IP 172.23.101.78.8080 > 195.49.180.253.43746: P 130:348(218) ack 205 win 514 08:24:45.082503 IP 172.23.101.78.8080 > 195.49.180.253.43746: F 348:348(0) ack 205 win 514 08:24:45.083625 IP 195.49.180.253.43746 > 172.23.101.78.8080: P 205:228(23) ack 349 win 123 08:24:45.083693 IP 195.49.180.253.43746 > 172.23.101.78.8080: F 228:228(0) ack 349 win 123 08:24:45.084047 IP 172.23.101.78.8080 > 195.49.180.253.43746: R 349:349(0) ack 228 win 0 08:24:45.084182 IP 172.23.101.78.8080 > 195.49.180.253.43746: R 3980471227:3980471227(0) win 0 08:24:50.078828 IP 195.49.180.253.43764 > 172.23.101.78.8080: S 209766624:209766624(0) win 14600 08:24:50.081892 IP 172.23.101.78.8080 > 195.49.180.253.43764: S 3264714030:3264714030(0) ack 209766625 win 8192

The problem is that there is traffic all the time (health monitor), please correct me if i’m wrong but you wont see any think from the VS (VIP address) as it will be making a new connection (reverse proxy) from the ASM IP address ? (VS is 195.49.180.208 and the ASM address is 195.49.180.253) is this not how it works ?

Wed Jun 25 08:34:19 BST 2014 info asm1 tmm1[11765] Rule /Common/New-Geowessex-Redirect : test.geowessex.com Wed Jun 25 08:34:19 BST 2014 info asm1 tmm1[11765] Rule /Common/New-Geowessex-Redirect : test.geowessex.com Wed Jun 25 08:34:19 BST 2014 info asm1 tmm1[11765] Rule /Common/New-Geowessex-Redirect : test.geowessex.com Wed Jun 25 08:34:19 BST 2014 info asm1 tmm1[11765] Rule /Common/New-Geowessex-Redirect : test.geowessex.com Wed Jun 25 08:34:25 BST 2014 info asm1 tmm[11765] Rule /Common/New-Geowessex-Redirect : test2.geowessex.com

Hi!

Did you include the three log functions below?

when HTTP_REQUEST {

    set host [string tolower [HTTP::host]]

    log local0. $host

    if { $host equals "test.geowessex.com" } {
        log local0. "Redirected based on $host"
        HTTP::redirect "https://test.geowessex.com/geoserver/"}
    elseif { $host equals "test2.geowessex.com" } {
        log local0. "Redirected based on $host"
        HTTP::redirect "https://vmcrgifme1"
    }

}

/Patrik