2014-04-02 66 views
1

我怎麼能把索引/目錄索引?如何把index /放在DirectoryIndex中? .htaccess

當我訪問這個URL localhost/mywebsite /我的網站沒有妥善安排 但是當我把localhost/mywebsite/index /它工作正常。

這裏是我的htaccess文件

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^/]+)/$ $1.php 
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ 
RewriteRule (.*)$ /$1/ [R=301,L] 

DirectoryIndex index.php index.php3 index.html index.htm index/ <-- i add this 

在此先感謝:)

PS。 localhost/mywebsite/index/= localhost/mywebsite/index.php 我只是隱藏我的網頁的文件擴展名爲/(斜線)。

+0

您的問題一個錯字;在你的問題中使用非工作URL都是'localhost/mywebsite /'。 –

+0

你也可以詳細說明你的實際問題,比「不恰當安排」更詳細。 – mario

+0

對不起。 localhost/mywebsite/index /我的意思是這個:D – Lestr1992

回答

1

它沒有任何意義,給DirectoryIndex,這是文件是被事件服目錄被直接訪問,另一個目錄列表。您可能只想重寫該目錄的所有內容。

假設你的htaccess文件是在/mywebsite/目錄中,再加入這個要頂:

RewriteEngine On 
RewriteCond %{REQUEST_URI} !^/mywebsite/index 
RewriteRule ^$ /mywebsite/index/ [L] 

,這樣它看起來像:

RewriteEngine On 
RewriteCond %{REQUEST_URI} !^/mywebsite/index 
RewriteRule ^$ /mywebsite/index/ [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^/]+)/$ $1.php 
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ 
RewriteRule (.*)$ /$1/ [R=301,L] 

DirectoryIndex index.php index.php3 index.html index.htm 
+0

我隱藏我的文件的擴展名,從.php到/(斜槓),localhost/mywebsite/index/= localhost/mywebsite/index.php,通常當我們訪問localhost/mywebsite /我們在localhost/mywebsite/index.php上重定向,對吧?當我accesslocalhost/mywebsite /所有圖像沒有找到問題。 – Lestr1992

+0

我想要發生的是當我訪問我的本地主機/ mywebsite /找到所有圖像或它將重定向到本地主機/ mywebsite/index/:) – Lestr1992