cancel
Showing results for 
Search instead for 
Did you mean: 

How to Rewrite the host header

SOLVED
srajesh.eee
Occasional Contributor

Re: How to Rewrite the host header

Current Setup:

we have a public facing web application and the url is http://sales.domain.com.  That user can then go to specific  web applications from that landing page and it is designated by specific url paths, in this case it will be http://sales.domain.com/products.  We have a traffic script that then redirects to a specific pool based on the url path which is a specific application.

Requirement:

  We are moving this specific application to a new datacenter that is running a different HA pair of traffic manager load balancers, but other applications under "http://sales.domain.com/otherapps" will remain in the current environment until all applications are migrated.  We want to redirect users to the new datacenter based on the url path  i.e "/products" alone now and retain the original url in the users browser, http://sales.domain.com/products.  It is important to retain the original url so the user experience is consistent. 

Currently we have registered a temporary dns http://newsales.domain.com and we are forwarding the traffic of "http://sales.domain.com/products" to this new dnsname along with the string after the hostheader (http://newsales.domain.com/products).

We are success upto here.

All we need to know whether the end user browser also can be changed back using Trafficscript to original url after the traffic reaches the new datacenter. i.e http://sales.domain.com/products without any routing issues and loopback traffic.

aannavarapu
Contributor

Re: How to Rewrite the host header

If you want the client browser to display the modified url based on traffic script, use the line http.changeSite($newurl).

If you want the client browser to display the old url even though traffic script modifies it, use the line http.setHeader( "Host", $newurl);

I hope this helps !!

srajesh.eee
Occasional Contributor

Re: How to Rewrite the host header

Hi Arun,

This is what I tried in the script but it is not working.. pls correct if any changes to be done in script

$url = http.getHostHeader();

$path = http.getPath();

$newurl = "www.sales.domain.com";

if( string.contains( $url, "www.newsales.domain.com" ) ) {

   http.ChangeSite( "$newurl/$path" );

  

   if ( string.startswith ($path, '/products')) {

pool.use ( "Pool-Salesproducts" );

}

  

}

aannavarapu
Contributor

Re: How to Rewrite the host header

Can you please elaborate on what is not working? Is the redirection not working or is the pool selection not working?

Based on my assumption of what is not working, try this:

$url = http.getHeader( "Host" );

if (string.contains( $url, "newsales" ) ) {

   $newurl = string.regexsub( $url, "newsales", "sales" );

   http.changeSite($newurl);

}

$path = http.getPath();

if ( string.startswith ($path, '/products')) {

pool.use ( "Pool-Salesproducts" );

}

srajesh.eee
Occasional Contributor

Re: How to Rewrite the host header

The change of url is not happening at end user level as it is sill showing the newsales.domain/products only in user browser.

aannavarapu
Contributor

Re: How to Rewrite the host header

Hi Rajesh,

The last code snippet provided to you is something that I tried in my setup and it works exactly like your requirement. I am not sure about what is happening at your end.    

The code you provided earlier is slightly different than mine. Please use the last one i suggested exactly and check. Try to put in log.info($newurl); right before the http.changeSite line and see the logs for the change.

Regards,

Arun

srajesh.eee
Occasional Contributor

Re: How to Rewrite the host header

We configured a new Pool with New URL IP in existing DC and all the existing URL Traffic  Pool is sent to this Pool.

And this worked for us.

Thanks Arun So much for your Support

Regards

Rajesh