【问题标题】:How to redirect to parameter? [closed]如何重定向到参数? [关闭]
【发布时间】:2013-06-01 10:05:28
【问题描述】:

将基于服务器的从http://example.com/example.php 重定向到http://example.com/example.php?date=2013-06-05 的最佳方式是什么?

【问题讨论】:

  • 基于什么标准?编码日期?您想在服务器级别(例如通过 Apache 的 mod_rewrite)还是在脚本中重定向?
  • header('Location : http://example.com/example.php?date=2013-06-05');
  • 不确定“重定向到参数”是什么意思?它不是一个单独的页面,只是$_GET 流中的一个参数。
  • 脚本中生成日期,例如G。 $date = time();。这是关于重定向过程,而不是日期。
  • if(!isset($_GET['date']))

标签: php redirect


【解决方案1】:

使用标题:

header('Location: http://example.com/example.php?date=2013-06-05');
exit;

如果你想根据今天的日期进行重定向:

header('Location: http://example.com/example.php?date=' . date('Y-d-m'));
exit;

【讨论】:

  • 位置的大写 'L' ...
  • 你应该使 url 相对。此外,您应该精确 !isset($_GET['date']) 测试以避免无限循环的重定向
  • 我不使用相对路径。我觉得他们很头疼。用 URL 定义一个常量并使用它会好得多。但是,为了方便起见,我使用了原始用户想要的 url。另外,在 PHP 手册中,php.net/manual/en/function.header.php 看第 6 条注释,HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme, hostname and absolute path, but some clients accept relative URIs
  • @Brewal 看看this。 URL 大部分时间都是作为相对 URL 工作的,但最好使用完整 URL 或绝对 URL 以确保兼容性。
  • @War10ck 感谢您的提示!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-27
  • 2014-07-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多