2014-04-02 61 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