Redirect to 3 different sites equally? html/htaccess/java/other?

Dee67

Golden Member
Dec 14, 2000
1,034
2
81
I'm driving myself nuts. I have been searching for days, just can't word a search to find exactly what I want so I'm hoping good old Anandtech will once again be my saving grace...

Please be gentle, I'm NOT a smart man.

What I'd like to do - is take a domain "exampledomain.com" and send its traffic equally to 3 other related domains while I figure some things out...

So basically looking for the easiest way to have ExampleDomain.com redirect/refresh/load as:

FirstDomain.com
or
SecondDomain.com
or
ThirdDomain.com


I don't care if it is 1 domain per load, per minute, per hour or even per day. I would just like the visitors going to ExampleDomain.com to end up at any one of the other 3 places... Location, screen size, browser, etc are not an issue or consideration.

I don't have server knowledge or access.. So cron copying an index.html meta refreshing to one of the names page every hour or whatever isn't my answer. (I barely remember that from working at an isp briefly in the 90's.)

It's on a virtual server, and as mentioned.. I'm old and not that bright.. so ftp to html/htaccess or whatever will have to be the level of access and/or difficulty.

In my head this seems simple enough but I just don't have the knowledge/skill to make it happen myself. And no matter how I'm wording my searches, I'm not finding anything all that close to what I'm trying to do.

I appreciate the time you took reading this and any/all help/suggestions, etc.. Thank you in advance!
 

Elixer

Lifer
May 7, 2002
10,376
762
126
Why did you post this in programming?
If you are asking to program it yourself, this is a pretty advanced subject, and no offense, but it don't seem like you have the skill set to make it happen.

This is the job of a load balancer. Bing/Google that, you will get plenty of solutions.
 

Dee67

Golden Member
Dec 14, 2000
1,034
2
81
As clearly stated in the message - I have been literally searching for days for a way to do this with no luck.

Is html/java not programming?

Load balancing? I think you're thinking too much of my little issue..
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,242
3,830
75
This seems to work:
Code:
<html><head></head>
  <body onload="sites=Array('http://www.google.com/', 'http://www.bing.com', 'http://www.yahoo.com/');window.location=sites[Math.floor(Math.random()*sites.length)];">
  Redirecting, please wait...
  </body>
</html>
Just change the sites in the Array.
 
  • Like
Reactions: Dee67

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
In scripting you just have a page on the first domain, have it generate a random number, then pick one of the other domains based on that number.

In PHP, you can have it add this redirect to the header it returns as a response.

Code:
<?php

// get RND
// set $url based on RND

?>
<HTML>
<HEAD>
<TITLE>Loading please wait</title>
<META HTTP-EQUIV=REFRESH CONTENT="0;URL=<?php echo $url; ?>">
</HEAD>
<BODY>&nbsp;</body>
</html>

In JavaScript, your page can do a document.location = x / = y / z

Code:
foo = Math.Random();
if ( foo < 0.33 )
document.location = x ;
else if ( foo< 0.666 )
...
 
  • Like
Reactions: Dee67

Dee67

Golden Member
Dec 14, 2000
1,034
2
81
This seems to work:
Code:
<html><head></head>
  <body onload="sites=Array('http://www.google.com/', 'http://www.bing.com', 'http://www.yahoo.com/');window.location=sites[Math.floor(Math.random()*sites.length)];">
  Redirecting, please wait...
  </body>
</html>
Just change the sites in the Array.

This is perfect!
...and so much more efficient than I even imagined.. a testament to your knowledge - thank you so much, I truly appreciate it :)