Forum Discussion

JustCooLpOOLe's avatar
JustCooLpOOLe
Icon for Cirrocumulus rankCirrocumulus
Oct 07, 2019

iRule Rewrite in Browser

Hi,

 

I'm hoping someone can help me out. We have an old domain moving from one system to another such as www.testsite.com. This domain is moving to another existing site but they don't plan to use that domain long term. I was thinking that I would update DNS for www.testsite.com to use the same A record as www.newtestsite.com and use an iRule on the VS for www.newtestsite.com that basically, looked for anything with www.testsite.com and rewrite so that the browser now references www.newtestsite.com and pass the traffic back to the existing pool.

 

Does that make sense?

  • You can use various things to rewrite the response page from the web page. Before you do that though, just check if you actually need to...

     

    The first option is relative links. If the website links are relative then the hostname can change and it wont affect he application at all. So this is a good option if it exists or can be enabled. YMMV

     

    The second option is the hostname of the site. This is often controlled by a single configuration option on a web application. Be it in the application itself or the virtual host configuration of the web server that is serving up the application. It is worth asking the question... does this setting exist and can it be modified?

     

    Finally when those options have been explored and discarded we need to do rewrites. The question now is is just 3xx redirects that need to be rewritten or all links. If it's just redirects then there are options in the HTTP profile that can help with re-writing redirects. This F5 DevCentral video touches on redirect rewrites as well.

     

    Then as the last option we have content rewriting and this is covered in some detail in this lab provided by F5. Essentially you define a search replace pattern which the F5 applies on response traffic. This pattern is surrounded by tokens. In it simplest format @find@replace@. Repeat for more replacements. This requires the F5 to inspect all return traffic and rewrite as needed.

     

    The order of the options above is based on F5 performance impact. The first two have no impact on the performance of the F5. The third has minimal. The last is the most demanding as it requires the F5 to scan all response traffic for an application.

  • Thanks  .

    I'm trying to avoid putting a redirect on a VS that could live forever so my thought was to point the IP for www.testsite.com to the same IP as www.newtestsite.com and have an iRule basically change the Host in the browser so the client wouldn't know the difference. Something like this?

     when HTTP_REQUEST {
    	
    	if { [HTTP::host] equals "www.testsite.com" } {
    		
    		[HTTP::header] replace Host "www.newtestsite.com"
    		
    	}
    	
    }

    Would that show as updated in the URL that the client would see? I've never replaced the host header and we typically do redirects so this is something new.