cancel
Showing results for 
Search instead for 
Did you mean: 

How to Rewrite the host header

SOLVED
srajesh.eee
Occasional Contributor

How to Rewrite the host header

Hi

Am trying rewrite the host header content using the below Traffic script

The Traffic which is coming on dns name "www.newsales.domain.com/x.x.x...x" needs to rewrite as "www.sales.domain.com/x.x...x"

All the string after / has to be retained.

f( http.getHeader( "Host" ) == "www.newsales.domain.com" ) {

http.setHeader( "Host", "www.sales.domain.com" );

}

But this rule is not getting executed after applying it.

Need the help to rewrite the part of host header to new host header

Regards

Rajesh

1 ACCEPTED SOLUTION

Accepted Solutions
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

View solution in original post

16 REPLIES 16
srajesh.eee
Occasional Contributor

Re: How to Rewrite the host header

The rule which am using is below and it is not working.

if( http.getHeader( "Host" ) == "www.newsales.domain.com" ) {

http.setHeader( "Host", "www.sales.domain.com" );

}

aannavarapu
Contributor

Re: How to Rewrite the host header

Hi Rajesh,

Can you try this?

$url = http.getPath(); 

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

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

   http.setPath( $newurl ); 

Thanks

Arun Annavarapu

srajesh.eee
Occasional Contributor

Re: How to Rewrite the host header

Hi Arun

I have applied this rule but it still the end user URL content was displaying the initial hit url only and not getting changed to the new url.

Regards

Rajesh

aannavarapu
Contributor

Re: How to Rewrite the host header

Hi Rajesh

Please use this and if it does not work, send me the event log before and after the rule.

$url = http.getPath();

log.info($url);

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

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

   http.setPath( $newurl );

log.info($newurl);

}



I changed the regex a bit.

If it works, remove the lines with log.info(


Arun

srajesh.eee
Occasional Contributor

Re: How to Rewrite the host header

Hi Arun,

Still it is not getting redirected to new url.

Here is the log info

We are getting the hit on Load Balancer on the Initial URL, but it is not getting changed to new url.

27/May/2014:16:56:46 -0700] "GET / HTTP/1.1" 200 429 "-" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.2; MS-RTC EA 2; MS-RTC LM 8)"

aannavarapu
Contributor

Re: How to Rewrite the host header

Hi Rajesh

Interesting that the log did not have the url.

Can you please try this and send me the log again?

$url = http.getHostHeader();

log.info($url);

aannavarapu
Contributor

Re: How to Rewrite the host header

Ok Rajesh,

I found the little caveat in your code.

Try this:

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

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

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

   http.setHeader( "Host", $newurl);

}

srajesh.eee
Occasional Contributor

Re: How to Rewrite the host header

Hi Arun

Here is the Script I tried and the output is below

$url = http.getHostHeader();

log.info($url);

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

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

   http.( $newurl );

log.info($newurl);

}

[27/May/2014:22:11:40 -0700] "GET sales.domain.com HTTP/1.1" 400 402 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko"

now the url is getting changed as per the log but it is not getting changed in the end user browser..

aannavarapu
Contributor

Re: How to Rewrite the host header

Good to know it worked. However, I did not see your question on changing the url in the client browser as well.

In any case, here is the complete code for changing the url based on request and on the client.

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

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

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

   http.changeSite($newurl);

}