Forum Discussion

Kevhed's avatar
Kevhed
Icon for Nimbostratus rankNimbostratus
Jan 19, 2016

Rewrite host domain URL

I've been looking thru many posts about rewriting and reverse proxy and cannot find what I'm looking for. I attempted to use a Rewrite Profile but that did not let me change the host/domain portion of the URL...it only allowed me to rewrite the part after the host/domain name. Hopefully this is not a repeat question but here I go.

 

This is what I am trying to do

 

  1. Internet user browses to mydomain-A.com/98/02/9802240_A.abc_Med.jpg
  2. This hits a vip/VS on my F5 and my F5 has a cert for this domain, so it accepts the ssl connection using a client ssl profile.
  3. I need the F5 to rewrite the domain part of this URL to mydomain-B.com/98/02/9802240_A.abc_Med.jpg and send this back to the server pool using a server ssl profile for the virtual server.

so my F5 will essentially be acting as a reverse proxy with rewrite and the client should not see the "mydomian-B" in the rewrite...but only the original "mydomain-A" that user browsed to.

 

thanks

 

3 Replies

  • Hi Kevhead,

     

    to rewrite the HOST name for the provided URI you could use this code...

     

    when HTTP_REQUEST {
        if { [string tolower [HTTP::uri]] equals "/98/02/9802240_a.abc_med.jpg" } then {
        HTTP::host "images.mydomain-b.com"
    }
    
    }
    

    Note1: For LTM deployments prior to v11.5, you have to the code below...

     

    when HTTP_REQUEST {
        if { [string tolower [HTTP::uri]] equals "/98/02/9802240_a.abc_med.jpg" } then {
        HTTP::header replace Host "images.mydomain-b.com" 
    }
    }
    

    Note2: The outlined code covers exactly your provided requirements. It changes the HTTP request for the given JPG file. If you need additional rewrites based on additional web directories or even for the entire site, then let us know. Be as precise as possible... 😉

     

    Cheers, Kai

     

  • Kevhed's avatar
    Kevhed
    Icon for Nimbostratus rankNimbostratus

    Thanks for all the replies...what a great forum. I ended up using this simple iRule and it worked perfectly.

     

    when HTTP_REQUEST { if { [HTTP::header host] eq "images.mydomain-A.com" } { HTTP::header replace Host "images.mydomain-B.com"

     

    }

     

    }