Learn F5 Technologies, Get Answers & Share Community Solutions Join DevCentral

Filter by:
  • Solution
  • Technology
Clear all filters
Answers

Rewrite URL using irule from internal to External

Hi All,

I am trying to rewrite URL from internal to external by applying the mask on header. It is working as expected using below irule however if I select some hyperlink or option, its showing actual url information which we would like to prevent that, as client should not recognize where they are getting redirected.In our example, I am forwarding users who are trying to access 123.abc.com/xyz/ to www.google.com, till here it is working as expected but after it got redirected, if I select any option or hyperlinks, its no rewrite the URL information.

when HTTP_REQUEST { if { [HTTP::host] eq "123.abc.com" and [HTTP::uri] contains "/xyz/" } { if {[string tolower [HTTP::uri]] contains "/xyz"}{ set uri [string range [HTTP::uri] 4 end] HTTP::uri $uri HTTP::header replace host "www.google.com"; pool testGoogle log local0. "[IP::client_addr]:[TCP::client_port]: Replacing Host with http://[HTTP::host]HTTP::uri" }}}

0
Rate this Question
Comments on this Question
Comment made 14-Sep-2018 by Pete White
when HTTP_REQUEST { 
    if { [HTTP::host] eq "123.abc.com" and [HTTP::uri] contains "/xyz/" } { 
        if {[string tolower [HTTP::uri]] contains "/xyz"}{ 
            set uri [string range [HTTP::uri] 4 end] 
            HTTP::uri $uri 
            HTTP::header replace host "www.google.com"
            pool testGoogle 
            log local0. "[IP::client_addr]:[TCP::client_port]: Replacing Host with http://[HTTP::host][HTTP::uri]" 
        }
    }
}

Presumably it doesn't rewrite the URI after the change because the host header of www.google.com no longer matches 123abc.com. Why aren't you just using a redirect to www.google.com?

0
Comment made 14-Sep-2018 by Hariharan_Padmanabhan 2

Hi Pete,

If I am redirecting to google, I am unable to rewrite the URL and also if we select some options like images or emails or any hyperlink, its showing the actual URL https://www.google.com/imghp?hl=en&tab=wi in the browser which we would like to prevent.

Thanks !

0
Comment made 14-Sep-2018 by Pete White

Presumably it does that because the new request comes in with a Host header of www.google.com so it doesn't match your iRule. I think you need to go back to the drawing board to work out what you want it to do and the flow because you're going to struggle otherwise. You could rewrite the HTML coming through, or make sure you send them to a page on which they can't access specific links ie everything is relative.

0
Comment made 14-Sep-2018 by Hariharan_Padmanabhan 2

Hi Pete,

Thanks for the suggestion ! Honestly I am new to irule configuration so I do not where to start and how to make it work but our ideal goal is to rewrite URL from internal to external website once its get redirected whatever we do, it should rewrite the URL information transparently without let the user know where they are actually getting redirected (Source URL). If you can give me some information, it would be appreciated. Thanks !

0

Answers to this Question