【问题标题】:PHP redirects without loopingPHP重定向而不循环
【发布时间】:2011-05-08 15:02:03
【问题描述】:

我有两个域,domain.com 和 main.com。我需要去 main.com 并返回 domain.com

如何在不循环的情况下进行这些重定向?而且我不能添加GET参数。

domain.comma​​in.comdomain.com

【问题讨论】:

  • 我不认为我很愚蠢,但我根本无法理解这个问题。
  • 重定向的目的是什么?
  • 检查一下然后回来

标签: php apache mod-rewrite redirect


【解决方案1】:

检查推荐人。

【讨论】:

  • 我知道我也不能在标题中设置引荐来源网址:(
【解决方案2】:

您可以在要重定向到其他位置的页面中使用header 函数:

header('LOCATION: url/page here');exit;

【讨论】:

    【解决方案3】:

    domain.com/get - 此时你可以添加一些额外的变量,然后如果你进入 domain.com 检查这个变量,如果这个变量存在于GET 然后不要进入 ma​​in.com/send

    如果您使用header() 更改位置,您可以在url 中添加一些get 变量,例如index.php?x。然后你可以检查isset($_GET['x']) 以获得它的存在。

    您不能在此表单中执行此操作。

    【讨论】:

    • 哈哈,你为什么不直接删除这个答案;)
    【解决方案4】:

    除此之外我没有找到其他解决方案:

    domain.com

    <?php
    if(!isset($_COOKIE['flag']))
    {
      setcookie('flag', 1, time() + 100, "/");
      header('location: http://main.com');
    }
    else
    {
      setcookie('flag', '', time() , "/");
      echo 'done!';
    }
    ?>
    

    ma​​in.com

    <?php
    header('location: http://domain.com');
    ?>
    

    【讨论】:

      猜你喜欢
      • 2015-03-21
      • 2014-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多