Hello,
I try to achieve something quite simple with Stingray traffic script.
I'de like to redirect all users to a specific path when they enter a website URL without specifying any PATH.
I first extract the path (splitted in a table for my needs)
$path = string.split( http.getPath(), "/" );
and the hostname
$hostname = http.getHostHeader();
Then I'de like to find a way to know when the user is in root folder in order to redirect him.
I tried many things but it doesn't seems to work well and I allways get errors messages about table.
For example if I do this
if ($path[1])
{
...
}
else
{
log.info("ROOT folder");
http.changesite( ...);
}
I get this error :
Array index out of bounds: index 1 is not less than size: 1
Anyone has an idea of a test I could perform to know if I'm in root foder ?
Thanks for your help :-)
Solved! Go to Solution.
Hi Gael.
Keep it simple... Try this...
if ( http.getPath() == "/" ) {
http.redirect( "http://www.riverbed.com/mainApp/" );
}
Change site will preserve the path, but the root folder is always "/" so it doesn't add any benefits.
Cheers,
Mark
Hello,
Let me respond my own question
I create an array with a NULL character inside and tested if the character was changed by my function or not.
This work fine and doesn't generate any errors anymore
$path = array.create(1,0);
$path = [""];
$path = string.split( http.getPath(), "/" );
if ($path[1] != ""){
#do something
}
else
{
#You are in the root folder
}
No that worked only one time and now I get the same error
Hi Gael.
Keep it simple... Try this...
if ( http.getPath() == "/" ) {
http.redirect( "http://www.riverbed.com/mainApp/" );
}
Change site will preserve the path, but the root folder is always "/" so it doesn't add any benefits.
Cheers,
Mark
Thanks
It works indeed.
With the array what I didn't noticed is that the first row will allways be NULL as the URL PATH begins with a /
so if I type www.example.fr/ the array will be [""]
If I type www.example.fr/test the array will be ["","test"]
Another simple test I could do is with the size of the array
if (array.length($path) == 1)
{
http.redirect( "www.example.fr/test" );
}