dopii22884 2014-05-23 17:23
浏览 19
已采纳

如何按特定顺序重定向我的网页? [关闭]

I'm looking for a way to redirect my webpage to two URLs in order, this could be in PHP but if you got any other ideas please hit me up! It should work like this:

Visitor 1 -> redirect to site1.com
visitor 2 -> redirect to site2.com
visitor 3 -> redirect to site1.com
visitor 4 -> redirect to site2.com

I think you get the idea :)

  • 写回答

2条回答 默认 最新

  • duandu1049 2014-05-23 17:40
    关注

    The main issue with this is you need info about the previous visitor.

    For this, you need to keep track of what each visitor is redirected to, so the next one will have access to the info.

    If you have only one webserver, this is easy. Just create an empty file for odds visits, and delete it for even visits.

     // Untested code, just to give the general idea
    
    $trackingFile='/usr/share/whatever/oddvisit';
    if(file_exists($trackingFile)){
        // even visitor
        unlink($trackingFile);
        Header('Location: http://url2.com');
        exit;
    }else{
        // odd visitor
        touch($trackingFile);
        Header('Location: http://url1.com');
        exit;
    }
    

    If you have multiple webservers, this is a little bit trickier.

    If you have no NFS all your webservers can access, you can store the odd/even info in a database. But it's best if you don't have a huge amount of trafic.

    If you have a lot trafic, I think the best solution would be to accept that each webservers will redirect visitors they get, independantly of what other webservers do. With very large numbers, you should get a pretty decent 50/50 redirections.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)