停止htaccess检测文件夹,而使用RewriteRule


Stop htaccess detecting folders as such and instead use RewriteRule

我怎么能停止。htaccess检测文件夹这样,而不是使用rewriterrule ?

我已经尝试了我找到的一切!

这是我当前的。htaccess:

Options -Indexes +FollowSymlinks
DirectorySlash Off
RewriteEngine On
#Block direct access to root php files
RewriteRule ^(init|404|_header|_footer|home)'.php$ index.php?error [L]
#Get doc
RewriteRule ^docs/([^/]+)/?$ index.php?doc=$1 [L]
#Get release
RewriteRule ^releases/([^/]+)/?$ index.php?release=$1 [L]
#Get page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/]+)/?$ index.php?page=$1 [L]

指出:

  • 我有文件夹docs, releasespages在服务器。
  • 我想给404错误的所有PHP文件,但index.php的根。

问题:

  • site.com(没有尾斜杠)抛出403错误,也因为Options -Indexes,但如果我删除它,它显示文件夹而不是加载默认页面。
  • 如果我删除DirectorySlash Off它解决了以前的问题,但当我去匹配文件夹的链接,它忽略了rewriterrules,然后附加其查询字符串(例如。site.com/docs/?page=docs)。当然,它显示了我想要的正确页面,但是,这个链接仍然困扰着我。

我该怎么做?

顺便说一句,我还必须添加第一个RewriteRule,以避免直接访问PHP文件在根目录。有没有一种方法可以动态地做到这一点,而不列出要阻止的文件?我尝试了deny,即使排除CSS, JS和图像,但我得到了意想不到的结果。
我想给404错误的所有PHP文件,但index.php的根。

完整的。htaccess:

DirectoryIndex index.php
Options -Indexes +FollowSymlinks
DirectorySlash On
RewriteEngine On
#Block direct access to root php files
RewriteRule ^(init|404|_header|_footer|home)'.php$ index.php?error [L]
RewriteRule ^$ index.php [L]
#Get doc
RewriteRule ^docs/(.*)$ index.php?doc=$1 [L]
#Get release
RewriteRule ^releases/(.*)$ index.php?release=$1 [L]
#Get page
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*[^/]+)/?$ index.php?page=$1 [L,QSA]