使用basename(_文件__)的PHP重定向在Windows Apache server中不起作用

使用basename(_文件__)的PHP重定向在Windows Apache server中不起作用,php,redirect,using,Php,Redirect,Using,我正在Windows7操作系统中构建web应用程序,运行Apache服务器、PHP5.3和MySQL 这个重定向不起作用 <?php // this is the path // C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\Biohouse\member\public\index.php $path = dirname(__FILE__).'\public\index

我正在Windows7操作系统中构建web应用程序,运行Apache服务器、PHP5.3和MySQL

这个重定向不起作用

    <?php
    // this is the path
    // C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\Biohouse\member\public\index.php

    $path = dirname(__FILE__).'\public\index.php';
    header("location: $path");


while this working

$path = '/public/index.php'
dirname(\uuuuu FILE\uuuu)
提供本地文件系统中文件夹的路径,而
/public/index.php
是Web服务器/vhost的文档根目录中的路径。您不能使用
\uuuuu文件\uuuuuu
创建URL。

尝试使用

$path = dirname(__FILE__).'\public\index.php'; header("location: $path");

看看PHPs神奇常数:

众所周知,为了保持跨平台的兼容性,通常应该使用反斜杠。为什么您更喜欢第一种方法?您没有区分物理路径(如c:\apache\htdocs)和url(如我使用str_replace)以及整个\replace to/但仍然不起作用。那么在这种情况下,我该怎么办?在MVC中,我们使用dirname()。问题不是
dirname()
,而是
\uuuu文件\uuu
。如果您
echo
\uuuuu文件\uuuuu
,您会注意到,它是文件系统上的文件路径。但是“Web服务器世界”是从文档根开始的。您可以尝试从将从
\uuuuu FILE\uuuuuu>获得的绝对路径中删除文档根目录。只要不使用
mod_rewrite`,或类似方法,这可能会起作用。(旁注:“MVC”是一种模式…)你基本上犯了完全相同的错误;看看这个函数返回的是路径,而不是url。。这就像你没有将用户重定向到谷歌,而是将他们重定向到/home/html/bla/bla/bla/或者像“嘿,请点击我的链接
对不起。我只看到了没有代码格式的帖子。我注意到的第一件事是
文件
而不是
\uuuuuuuuuuu文件