2011-02-18 36 views
1

我有一個場景,我有兩個文件,一個是index.php,另一個是index.htm。htaccess重寫場景

我將如何設置重寫條件/規則,以便如果index.htm在子目錄中的服務器上存在,請將請求傳遞給此文件。如果文件不存在,則將請求傳遞給/index.php?

回答

1

這取決於你的子目錄結構,而是一個解決方案是簡單地使用專門的index.php,並寫一些PHP在index.php文件的前檢查其他文件的存在:

if(file_exists("subfolder/index.htm")) exit(file_get_contents("subfolder/index.htm")); 

否則,檢查出標誌爲的RewriteCond

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

+0

是的,這是非常感謝! :) – 2011-02-18 21:50:09

0

無需重寫,使用DirectoryIndex絕對路徑:

DirectoryIndex index.htm /index.php