Reputation: 2647
I am working on a LAMP(PHP) stack.
Scenario - I want to redirect the incoming traffic to the site to a different website based on a percentage.
Example : Main www.a.com. I have few other sites - www.a1.com, www.a2.com, www.b1.com, www.b2.com.
Now when the traffic comes to my main site www.a.com, I would like to divide the traffic like -
33% of traffic redirected to www.a1.com
33% of traffic redirected to www.a2.com
30% of traffic redirected to www.b1.com
4% of traffic redirected to www.b2.com
how can i achieve this? I am a php developer so would like to do it through php, but also would like to know if any other technologies are involved. ------ updates ----
I want to achieve this functionality once the user clicks on the logout button on the main site. Thanks, Tanmay
Upvotes: 0
Views: 2102
Reputation: 1
I have a few cents:
This is one base logic. You can expand or think similar lines.
If you have a firewall application, you might have the redirection settings based on %ge available there.
Thanks.
Upvotes: 0
Reputation: 5974
$route_decider = rand(0, 99);
/**
/* Remember there should not be an output before the header response. Browsers must see HTTP header
/* response first! Upon logout redirect to a page containing this code.
/*
**/
if ( $router_decider >= 0 && $route_decider <= 32) # 33 %
header( 'Location: http://www.a1.com' );
if ( $router_decider >= 33 && $route_decider <= 65) # 33 %
header( 'Location: http://www.a2.com' );
if ( $router_decider >= 66 && $route_decider <= 95) # 30 %
header( 'Location: http://www.b1.com' );
if ( $router_decider >= 96 && $route_decider <= 99) # 4 %
header( 'Location: http://www.b2.com' );
Upvotes: 0
Reputation: 45282
Generate a random number between 1 and 100,
0-32 redirected to www.a1.com
33-65% redirected to www.a2.com
66-95% redirected to www.b1.com
96-99% redirected to www.b2.com
you can provide these functionalities using your server. Check out those keywords: nginx, round robin.
Upvotes: 3