2012-08-10 73 views
0

我有以下目录文件结构;错误的文件包括在IIS上

/index.php 
/head.inc (upper) 
/subdir/page.php 
/subdir/head.inc (lower) 

在/subdir/page.php我有一个重定向到上一级的index.php

header("location: ../index.php"); 

在index.php文件中存在的包括( 'head.inc')指令。

在Apache服务器上,加载了正确的head.inc(upper) - 来自index.php所在的同一个(webroot)目录中的head.inc。在IIS上,加载了不正确的head.inc(下) - 来自/ subdir /的head.inc,其中page.php驻留在其中进行重定向!这是国际空间站的一个错误吗?

+3

请注意,根据标准,位置标头应该是**绝对**。尝试解决这个问题,看看问题是否存在。 (这是一个远射,但到底是什么) – 2012-08-10 22:20:19

+0

我需要保持相对路径,因为有时候我会在Web服务器根目录上部署我的Web应用程序,并在某些时候在WebApp子文件夹中部署我的Web应用程序。但是,IIS如何自行决定加载哪些文件(从根目录或子文件夹加载)。我将upper head.inc更名为top.inc并更改了include('top.inc')。以前IIS从subdir加载.inc文件,现在从根目录中,其中index.php是预期的!奇怪的IIS行为。以dirname(__ FILE__)形式存在的 – sbrbot 2012-08-10 22:32:35

回答

1

尝试生成自己的完整路径。例如:

// Get the parent directory 
$parent_directory = basename(dirname(dirname(__FILE__))); 

header("Location: $parent_directory/index.php"); 
+0

./以及dirname(dirname(__ FILE__))形式的../在IIS和Apache服务器上的工作方式相同, – sbrbot 2012-09-01 20:58:06