Forum Discussion

puluck's avatar
puluck
Icon for Cirrus rankCirrus
Oct 16, 2017

Redirection of URL without changing the host header

Hello Everyone

 

I have requirement where i need to send traffic to external blog site based on URI but host header of client browser should display the original URL.

 

https://www.abc.com/apple/ should get response from ebc.mysite.com .

 

When HTTP_REQUEST{ if { [HTTP::uri] equals "/apple" } { node 193.13.14.5 snat automap HTTP::header replace Host "ebc.mysite.com" HTTP::uri/ } }

 

I have tried several irules but nothing is working .

 

request your help here .

 

Thanks

 

  • Hygor's avatar
    Hygor
    Icon for Nimbostratus rankNimbostratus

    Using equals in your condition means that the uri should be exactly /apple. If the request is /apple/ it will not trigger the condition. I suggest change the condition to contains or starts_with and use a space after HTTP::uri

    when HTTP_REQUEST { 
        if { [HTTP::uri] contains "/apple" } { 
            node 193.13.14.5 
            snat automap 
            HTTP::header replace Host "ebc.mysite.com" 
            HTTP::uri / 
        } 
    }
    

    Also you can use a rewrite profile to rewrite the uri in question and remove the

    HTTP::uri /
    from the iRule.

  • I've not tested this iRule but the idea is the re-write the host header on HTTP_REQUEST and re-write it back to the original value on HTTP_RESPONSE - resulting the client being unaware this has been changed.

    You could also use a Stream expression in an iRule to do this.

    when HTTP_REQUEST {
        set originalHost "[HTTP::host]"
        set newHost "ebc.mysite.com"
        if {[HTTP::uri] starts_with "/apple"} {
            node 193.13.14.5
            snat automap
            HTTP::header replace Host $newHost
            HTTP::uri / 
        }
    }
    
    when HTTP_RESPONSE {
        if {[HTTP::host] equals $newHost} {
            HTTP::header replace Host $originalHost
        }
    }
    
  • When i tried to access the URL it gives error as BAD request .Your Browser sent request that this server could not understand .You are speaking plain HTTP to an SSL enabled server port .

     

    URL is directly accessible on http not sure why its giving this error