Apache .htaccess设置,用于处理索引文件、尾部斜杠和文件扩展名

Apache .htaccess设置,用于处理索引文件、尾部斜杠和文件扩展名,apache,.htaccess,redirect,mod-rewrite,Apache,.htaccess,Redirect,Mod Rewrite,我的网站是相当标准的,在文件夹中包含一堆索引文件。即: folder1 > index.php > some-file.php sub-folder1 > index.php sub-folder2 > index.php folder2 > some-file.html index.html 我最近做了一些.htaccess更改,允许用户输入不带.ht

我的网站是相当标准的,在文件夹中包含一堆索引文件。即:

 folder1
      > index.php
      > some-file.php
      sub-folder1
           > index.php
      sub-folder2
           > index.php
 folder2
      > some-file.html
 index.html 
我最近做了一些.htaccess更改,允许用户输入不带.html扩展名的文件名,但仍然指向服务器上的正确文件。它还应该删除后面的斜杠。这是我的root.htaccess文件中的代码:

 DirectoryIndex index.html
 RewriteEngine On

 # remove trailing slash
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
 #RewriteRule ^(.+?)/$ /$1 [R,L]
 RewriteRule ^(.+?)/$ /$1 [R=301,L]

 # To internally forward /dir/file to /dir/file.html
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{DOCUMENT_ROOT}/$1.html -f [NC]
 RewriteRule ^(.+?)/?$ /$1.html [L]
这似乎适用于html文件。例如包括以下链接:

folder2/一些文件

但是,当我链接到
folder1/
时,索引文件是一个php文件,我将被指向folder1中的文件和文件夹列表。我希望该行为会调出
index.php
而不是文件列表

如果我将整个路径包含在一个链接中,比如:
folder1/index.php
,它就可以正常工作

当我在上面添加.htaccess设置时,这种行为都发生了变化。在此之前,我的网站上甚至没有.htaccess文件。我假设它与.htaccess文件中的代码有关,但是,我不知道如何修复它,因为代码是我在帮助论坛上找到的

我还注意到,在更改.htaccess设置之前,我可以从任何页面链接到我的root
index.html
,浏览器只显示
www.domain.com
。现在它总是显示
www.domain.com/index


想知道是否有人知道我应该在.htaccess文件中使用的正确设置

您制作了
DirectoryIndex.html
,如果目录中没有
index.html
,即使目录中有
index.php
,也会列出

添加如下内容:

DirectoryIndex index.html  index.php

所以,若并没有
index.html
请求,对目录的请求将转到
index.php

您制作了
DirectoryIndex.html
,如果目录中没有
index.html
,即使目录中有
index.php
,也会列出

添加如下内容:

DirectoryIndex index.html  index.php
所以,若并没有
index.html
请求,对目录的请求将转到
index.php