2015-07-21 45 views
1

可以說,我有我的根目錄區:.htaccess爲具有可變數目的目錄的url加載索引文件?

root/regions 

我想加載它位於地區index.php文件夾,如果用戶訪問下列之一:

http://www.example.com/regions/united-kingdom 
http://www.example.com/regions/united-kingdom/london 
http://www.example.com/regions/united-kingdom/londom/rm8-16de 

國家,城市和郵政編碼不存在目錄! 如何做到這一點? 預先感謝您!

回答

1

在你regions/.htaccess,你可以有這樣的.htaccess:

DirectoryIndex index.php 
RewriteEngine On 
RewriteBase /regions/ 

# If the request is not for a valid directory 
RewriteCond %{REQUEST_FILENAME} !-d 
# If the request is not for a valid file 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule . index.php [L] 
+1

這就是我所說的師父! :)謝謝你anubhava!和往常一樣好:) – Europeuser

+0

Anubhava,請你看看這個問題:http://stackoverflow.com/questions/39014697/htaccess-how-to-load-index-file-from-specific-directory?noredirect=1 – thecore7

0

該順序應該是DirectoryIndex index.html index.php //默認是index.html。

如果Web服務器在當前目錄中找不到與DirectoryIndex指令中的名稱匹配的文件,則會向瀏覽器顯示一個目錄列表,顯示當前目錄中的所有文件。 Apache將按順序查找每個上述文件,並在訪問者請求一個目錄時查找它發現的第一個文件。

一旦檢查DirectoryIndex這是您的解決方案。

讓我知道你是否面對任何查詢/關注此事。

謝謝!

+0

你好,謝謝你對我的幫助。我認爲你的做法是錯誤的。 DirectoryIndex index.html index.php將有助於只有當我訪問http://www.example.com/regions但其他/國家/城市/郵政編碼將無法幫助,因爲他們不存在作爲文件夾,我會得到錯誤500,如果我嘗試訪問..目錄索引是不是解決方案! – Europeuser