Forum Discussion

sidiov's avatar
sidiov
Icon for Nimbostratus rankNimbostratus
Jan 11, 2012

transparent redirect question

Hi,

 

I want to take a request to a domain that contains a string and redirect based on that string without the client knowing a redirect took place (ie. getting different content based on that string - rather than being redirected based on that string)

 

 

The other part is that string needs to be removed during that request, because it doesn't actually exist.

 

Based on other stuff in devcentral, I was trying the following code, but it seems to be doing the exact opposite of what I want, its rewriting the header on the client side but pulling the data from the original host.

 

 

 

when HTTP_REQUEST {
if { [string tolower [HTTP::uri]] contains "/11string11"}
{
  set uri [string map  {"/11string11" ""}  [HTTP::uri] ]
   HTTP::header replace "Host" "beta-s.domain.com"
   HTTP::uri "$uri"
}
}

 

 

beta-s.domain.com is just a host out somewhere else not another vip/pool

 

So my goal is to have the request for http://s.domain.com/11string11/junk.txt return the content from http://beta-s.domain.com/junk.txt while keeping the original name on the client.

 

 

 

5 Replies

  • Colin_Walker_12's avatar
    Colin_Walker_12
    Historic F5 Account
    Are you looking to do this for just a single host/uri combination, or several? It would change the approach a fair amount if there were many of these. Also, do you need to re-write content (links, image source addresses, etc.) inside the document that you're serving from behind the altered host/uri?

     

     

    This is definitely possible, but you'll need to have a mapping of before/after URLs so the LTM knows which page to forward things to, and the approach will vary based on what you're trying to achieve.

     

     

    Colin
  • sidiov's avatar
    sidiov
    Icon for Nimbostratus rankNimbostratus

    Technically its for 2 hosts, but right now I was doing them in seperate irules since the original sites are seperate VIPs. I dont imagine I would need to go beyond a single host rewrite per site. (Its just used for developers to test a beta version of that site using a production caching layer)

     

     

    The number of uris would be huge, although they all would use the same placeholder guid, just the content at the end would change, I wouldnt want to map them all specifically since its over 100,000 different items and fairly dynamic.

     

    I dont think I will need to rewrite content inside the doc, in general the link should only be calling to specific content, like css / js files.

     

  • the rule looks just fine for me. may you capture packet to see what is going on?

    [root@ve1023:Active] config  b virtual bar list
    virtual bar {
       snat automap
       pool foo
       destination 172.28.19.79:80
       ip protocol 6
       rules myrule
       profiles {
          http {}
          tcp {}
       }
    }
    [root@ve1023:Active] config  b pool foo list
    pool foo {
       members 200.200.200.101:80 {}
    }
    [root@ve1023:Active] config  b rule myrule list
    rule myrule {
       when HTTP_REQUEST {
            if { [string tolower [HTTP::uri]] contains "/11string11"}{
                    set uri [string map  {"/11string11" ""}  [HTTP::uri] ]
                    HTTP::header replace "Host" "beta-s.domain.com"
                    HTTP::uri "$uri"
            }
    }
    }
    
    [root@ve1023:Active] config  ssldump -Aed -nni 0.0 port 80
    New TCP connection 1: 172.28.19.253(38669) <-> 172.28.19.79(80)
    1326337897.9044 (0.0018)  C>S
    ---------------------------------------------------------------
    HEAD /11string11/junk.txt HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8r zlib/1.2.3 libidn/0.6.5
    Host: 172.28.19.79
    Accept: */*
    
    ---------------------------------------------------------------
    
    New TCP connection 2: 200.200.200.10(38669) <-> 200.200.200.101(80)
    1326337897.9064 (0.0009)  C>S
    ---------------------------------------------------------------
    HEAD /junk.txt HTTP/1.1
    User-Agent: curl/7.15.5 (i686-redhat-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8r zlib/1.2.3 libidn/0.6.5
    Host: beta-s.domain.com
    Accept: */*
    
    ---------------------------------------------------------------
    
  • sidiov's avatar
    sidiov
    Icon for Nimbostratus rankNimbostratus

     

    tcpdump info shows the first call from the client, and then the redirect call....

     

    edit

     

    ...but...

     

    I tried with an apache box as the target, and noticed that the host and uri is getting changed but the content is still coming from the original (iis) servers

     

    (b.domain.com is apache server)

     

     

     

     

    HTTP/1.1 301 Moved Permanently

     

    Content-Type: text/html; charset=UTF-8

     

    Location: http://b.domain.com/test.txt/

     

    Server: Microsoft-IIS/7.5

     

    X-Powered-By: ASP.NET

     

    Date: Thu, 12 Jan 2012 21:43:40 GMT

     

    Content-Length: 156

     

     

    Document Moved

     

     

    test.txt does not exist on s.domain.com but does on b.domain.com, which explains the appended trailing slash I see - the iis boxes rewrite the 404 page.

     

    But I want to load the content from the other server whether it exists in the first domain or not.

     

     

     

  • But I want to load the content from the other server whether it exists in the first domain or not.if you want to send traffic to another server (pool member), can you try node command?

    node wiki

    http://devcentral.f5.com/wiki/iRules.node.ashx

    e.g.

    when HTTP_REQUEST {
       if { [string tolower [HTTP::uri]] contains "/11string11"}{
          set uri [string map  {"/11string11" ""}  [HTTP::uri] ]
          HTTP::header replace "Host" "beta-s.domain.com"
          HTTP::uri "$uri"
          node x.x.x.x 80
       }
    }