【问题标题】:mod_rewrite external links issue (wordpress)mod_rewrite 外部链接问题(wordpress)
【发布时间】:2012-11-11 00:22:30
【问题描述】:

我有一个 redirect.php 和一个链接,但它在 WORDPRESS 中不起作用。

我希望当我点击我网站上的“hello”链接时,它会转到 redirect.php,用户看到微调器 5 秒,然后用户退出我的网站到 hello.com

mod_rewrite 似乎有问题,我无法解决

我非常感谢您提供非常详细的答案。我很年轻

这就是我所拥有的。

1.- 我的主页上有一个外部链接:

<a href="http://redirect.php?link=hello.com">Hello</a>

2.- 在redirect.php 中,我有:

<html>
<head>
    ...
    <meta http-equiv="refresh" content="5;url=<?php echo $_GET['link'];?>" />
    ...
</head>
<body>
    <h1>You are leaving my site!</h1>
    <img src="/images/spinner.gif" alt="spinner" />
</body>
</html>

【问题讨论】:

    标签: mod-rewrite redirect url-rewriting external


    【解决方案1】:

    链接&lt;a href="http://redirect.php?... 不正确。这很可能是&lt;a href="/redirect.php?... 或您服务器上的任何子目录。

    您还应该在链接参数中包含协议或将其添加到元标记中。还要确保对元标记中的链接进行 HTML 编码,并在链接参数中正确地对域名进行 URL 编码。

    所以,把链接改成:

    <a href="/redirect.php?link=http%3A%2F%2Ftest.com">Hello</a>
    

    如果您的网站根目录中有redirect.php 文件。并将元标记更改为:

    <meta http-equiv="refresh" content="5;url=<?php echo htmlentities($_GET['link'], ENT_QUOTES,);?>" />
    

    您可能想对链接参数的有效性进行一些验证,并且您可能还想检查引荐来源网址 ($_SERVER('HTTP_REFERER')) 以确保您只对来自您自己网站的链接执行重定向(即不要' t 创建open redirect 漏洞)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-27
      • 1970-01-01
      • 2014-04-24
      • 1970-01-01
      • 2020-10-15
      • 2014-03-19
      • 1970-01-01
      相关资源
      最近更新 更多