2012-08-10 46 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