【问题标题】:How to redirect and/or delay depending on referrer?如何根据推荐人重定向和/或延迟?
【发布时间】:2013-10-07 16:27:17
【问题描述】:

我希望仅允许来自某个引用 URL(例如“example.com/123”)的流量访问我的网站。我希望在特定延迟(例如 1 或 2 分钟)后将其余流量重定向到相同的引用 URL。我要流量 来自 example.com/123 不再提及。

我想过使用这样的东西,但我不知道如何编辑以满足我的要求:

<?php
$referrer = $_SERVER['HTTP_REFERER'];
if (preg_match("/site1.com/",$referrer)) {
      header('Location: http://www.customercare.com/page-site1.html');
} elseif (preg_match("/site2.com/",$referrer)) {
      header('Location: http://www.customercare.com/page-site2.html');
} else {
      header('Location: http://www.customercare.com/home-page.html');
};
?>

【问题讨论】:

    标签: php .htaccess redirect referrer


    【解决方案1】:

    您需要在您的 php 脚本中添加一些影响 页面 标题的内容,而不是实际服务器响应的标题。

    因此,在生成页面标题的脚本部分中,您需要这样的内容:

    <!-- this is the header of your page -->
    <head>
      <title>Your Title</title>
      <?php
        $referrer = $_SERVER['HTTP_REFERER'];
    
        // if referer isn't from example.com/123 we setup a redirect
        if ( !strstr($referrer, '://example.com/123') )
           print ('<META HTTP-EQUIV=Refresh CONTENT="60; URL=http://example.com/123">\n');
    
        ?>
      <!-- maybe some other stuff -->
    </head>
    

    所以如果引用者不是来自http://example.com/123,那么这行将被插入到标题中:

    <META HTTP-EQUIV=Refresh CONTENT="60; URL=http://example.com/123">
    

    告诉浏览器在 60 秒后重定向到 URL(在本例中为 http://example.com/123)。

    【讨论】:

      猜你喜欢
      • 2012-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多