Hi All,
I'm looking for the best way to preserve static links from an 'old' site when the site moves to a new infrastructure behind a Riverbed Stingray using TrafficScript.
What we are trying to do is this:
$path = http.getpath();
if( http.getheader( "Host" ) == "www.oldsite.com.au"
&& string.contains( $path, "oldpath/faqs" ) ){
http.changeSite( "http://www.newsite.com.au/newpath/faq" );
}
But we are trying to do it for 200+ differing links that may very well get updated frequently by our customer. The perfect scenario would be to have a traffic script rule reference a file that has <from link> TAB <to link> that we can upload via extra files as it is changed, and have the rule read the changes. The only other requirement is that the redirects have to be 302's ie permanent redirects.
Any suggestions guys?
Solved! Go to Solution.
Adam,
Firstly, welcome to Splash!
Let me start at the "teach a man to fish" level and give you some building blocks to use in this case:
Remember that the TrafficScript reference is on every STM and is available from the TrafficScript editing page and has sample code for each of the functions I have listed above:
https://<YOUR STM IP OR HOSTNAME>:9090/apps/zxtm/help.fcgi?section=TrafficScript%20Reference
Adam,
Firstly, welcome to Splash!
Let me start at the "teach a man to fish" level and give you some building blocks to use in this case:
Remember that the TrafficScript reference is on every STM and is available from the TrafficScript editing page and has sample code for each of the functions I have listed above:
https://<YOUR STM IP OR HOSTNAME>:9090/apps/zxtm/help.fcgi?section=TrafficScript%20Reference
Now that we have done the "Teach a Man to Fish" listing, here is a sample rule written by my esteemed colleague Michael Granzow that should do the trick. I have pinged Michael offline as I believe there was something he wanted to tune on this rule, so he might jump in and make some modifications, but here is the rule here:
TrafficScript To Map Old URL's to New URLs
Thanks Aidan,
Ive tested the script and whilst it works as designed, what we are trying to do is subtly different.
The best way to describe the difference is to refer to the comments in the script
Line 3, old URL, is specified as a /path not as a http://newsite.com/url, which is what we require.
I was thinking one solution would be to add an extra column in the text file called host between the RW and the url ie row 2, and then search for both but Im not sure how this would affect the optimisation code.
Anyone suggest the best method to achieve this?
Hi Adam,
You can modify the code in Michael Granzow's article TrafficScript To Map Old URL's to New URLs to cater for the file format you want. i.e. full URLs in the second column of the file.
Line 160 - where the code is: $path = http.getPath(); - extend that as follows:
# Set $path to be full URL e.g. https://site.com/cgi-bin/login.cgi
# Assumes that you are running http and https on the standard ports
if( ssl.isSSl() ) {
$path = "https://" . http.getHostHeader() . http.getPath();
} else {
$path = "http://" . http.getHostHeader() . http.getPath();
}
Then, a little further down, line 177 - where the code is http.setPath( $rwPath );, change that to:
if( string.regexMatch( $rwPath, "https?://([^/]*)(.*)" ) ) {
http.setHeader( "Host", $1 );
http.setPath( $2 );
break;
} else {
log.warn( "checkPaths returned malformed URL: '".$rwPath."'" );
}
Then you can use a redirect file that contains full URLs like the following
RW http://stingray/foo http://stingray/bar
RW http://stingray/foo/bar http://stingray/baz
RW http://stingray/bar http://stingray/grub
RW http://stingray/1foo* http://stingray/bar
RW http://stingray/1foo/bar* http://stingray/baz
RW http://stingray/1bar* http://stingray/grub
RW http://stingray/1foo/* http://stingray/bar
RW http://stingray/1foo/bar/* http://stingray/baz
RW http://stingray/1bar/* http://stingray/grub
and Michael's rule works fine.
Best regards
Owen
Hi Owen, Aidan, All,
I got this working, but I had to modify the way we processed a redirect, as follows:
Instead of line 177 - where the code is http.setPath( $rwPath );, changed that to:
http.setPath( "" );
http.changeSite( $rwPath );
instead, and we are now working as expected!
Thanks all for your help!