【问题标题】:PHP Header Location is not working in localhost xampp?PHP Header Location 在 localhost xampp 中不起作用?
【发布时间】:2016-09-11 22:57:40
【问题描述】:

我正在尝试使用 xampp 中的标头位置重定向页面,但它不起作用并重定向到 localhost/dashboard

我使用以下代码在 localhost 中进行简单重定向,我将我的站点放在 htdocs/test/ 中,其中的文件是 index.html 和 index.php,index.php 代码如下

<?php 
      header("Location:/index.html");
 ?>

当我尝试访问 http://localhost/test/index.php 时,它不会访问 localhost/test/index.html 但它正在重定向到http://localhost/dashboard/

【问题讨论】:

标签: php apache .htaccess redirect xampp


【解决方案1】:

尝试:

<?php
echo "<script type=\"text/javascript\" language=\"javascript\">
        window.location.replace(\"index.html\");
      </script>";

?>

【讨论】:

  • 回答问题时,请提供一些背景信息。 为什么这是答案? 为什么这行得通?
【解决方案2】:

我知道你的问题,这应该可以解决它。

在你的 index.php

<?php 
header('Location: ./index.html');


?>

其中./代表当前目录

【讨论】:

    【解决方案3】:

    检查您的 php.ini 文件中 output_buffering=On;然后使用此代码重定向到 index.html

    <?php 
    ob_start();
         if (headers_sent()) {
    		 
        die("Redirect failed.");
    }
    else{
        exit(header("Location: index.html"));
    }
    ?>

    您可以从这里http://php.net/manual/en/function.ob-start.php获取ob_start的详细信息

    【讨论】:

    • 同样的问题,即使使用它是htaccess文件有任何问题
    • 您是否检查了您的 php.ini 文件中的 output_buffering。是开还是关?如果它关闭,则 ob_start() 将不起作用。您是否也将 /index.html 替换为 index.html?
    • 是的,我检查了 php.ini 文件输出缓冲是否打开,我只是复制了您的代码并放置并检查了没有工作同样的问题
    • 试试这个:更改行 exit(header("Location: index.html"));退出(header(“位置:index.html”,true,301));暂时重命名您的 htaccess 文件并重新启动您的服务器。检查它现在是否正确重定向。
    猜你喜欢
    • 2021-11-06
    • 1970-01-01
    • 2017-08-07
    • 2022-01-16
    • 2015-11-22
    • 2011-11-03
    • 2013-07-10
    相关资源
    最近更新 更多