jtanmay
jtanmay

Reputation: 2647

how to redirect a % of traffic to different websites?

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

Answers (3)

KL-Tech
KL-Tech

Reputation: 1

I have a few cents:

  1. Put a proxy server as your initial target website. www.main-domain.com
  2. Add a script here to divert your traffic
  3. Diversion is based on %ge of traffic, so write code for counting your visitors to your main domain.
  4. Make a session for your counter and start diverting. Count the per domain diversions and put in session.
  5. Always check the session counter and make this redirection.

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

Steve Nguyen
Steve Nguyen

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

ahmet alp balkan
ahmet alp balkan

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

Related Questions