Replace subdomain and remove path

Greetings,

I’m struggling with this :

I would like this : http://www.mysite.org/customfiles/mydoc.htm transformed into this: http://customfiles.mysite.org/mydoc.htm

Of course, there are several files, mydoc.htm is just an example. And the original site www.mysite.org must not be affected.

Note : This URL will be forwarded to a pool so I cannot use redirect.

I’ve written the following iRule:

when HTTP_REQUEST {
if { [HTTP::path] starts_with "/customfiles"} {
  HTTP::path [string replace [HTTP::path] 0 12 ""]
  HTTP::header replace Host "customfiles.onprvp.fgov.be"
  pool my_pool
}
}

And nothing happens. In the F5 logs we only have a warning message saying the rule already exists on partition Common, but nothing else.

I suspect that the string replace isn’t very happy but a string map gives the same.

What am I doing wrong ? :slightly_smiling_face:

Olivier, by no means an expert but I’d use string range instead e.g.

HTTP::path [string range [HTTP::path] 0 12]

Does this work for you?

N

It may be beneficial to verify that hyperlinks on those pages will continue to point to valid URLs.

I think counting may be the problem :-);

when HTTP_REQUEST {
    if { [HTTP::path] starts_with "/customfiles"} {
        HTTP::uri [string replace [HTTP::path] 0 11 ""]
        HTTP::header replace Host "customfiles.onprvp.fgov.be"
        pool my_pool
    }
}

Hello all,

Thanks very much for your answers.

I have tried your suggestions but unfortunately it does not work :frowning:

I keep on searching and keep you informed of the results.

Olivier

(Sorry for my late answer, just came back from a few days off)

I have tried your suggestions but unfortunately it does not work :frowning:

have you run tcpdump to see what wrong is?

e.g.

config

root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm virtual bar
ltm virtual bar {
    destination 172.28.24.10:80
    ip-protocol tcp
    mask 255.255.255.255
    pool foo
    profiles {
        http { }
        tcp { }
    }
    rules {
        myrule
    }
    source 0.0.0.0/0
    source-address-translation {
        type automap
    }
    vs-index 2
}
root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm pool foo
ltm pool foo {
    members {
        200.200.200.101:80 {
            address 200.200.200.101
        }
    }
}
root@(ve11a)(cfg-sync In Sync)(Active)(/Common)(tmos) list ltm rule myrule
ltm rule myrule {
    when HTTP_REQUEST {
  if { [HTTP::path] starts_with "/customfiles/" } {
    HTTP::uri [string map {/customfiles/ /} [HTTP::uri]]
    HTTP::header replace Host "customfiles.mysite.org"
  }
}
}

 trace

[root@ve11a:Active:In Sync] config  ssldump -Aed -nni 0.0 port 80
New TCP connection 1: 172.28.24.1(36831) <-> 172.28.24.10(80)
1391521795.0090 (0.0011)  C>S
---------------------------------------------------------------
GET /customfiles/mydoc.htm HTTP/1.1
User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
Accept: */*
Host: www.mysite.org

---------------------------------------------------------------

New TCP connection 2: 200.200.200.14(36831) <-> 200.200.200.101(80)
1391521795.0275 (0.0173)  C>S
---------------------------------------------------------------
GET /mydoc.htm HTTP/1.1
User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8b zlib/1.2.3 libidn/0.6.5
Accept: */*
Host: customfiles.mysite.org

---------------------------------------------------------------

and logging;-

when HTTP_REQUEST {
    if { [HTTP::path] starts_with "/customfiles"} {
        log local0. "Replacing [HTTP::uri] with [string replace [HTTP::path] 0 11 ""]"
        HTTP::uri [string replace [HTTP::path] 0 11 ""]
        log local0. "Replaced - \[HTTP::uri\] is [HTTP::uri]"
        HTTP::header replace Host "customfiles.onprvp.fgov.be"
        pool my_pool
    }
}