我有一个遗留在Apache上的网站。 它有许多网页位于公共Web根目录及其子文件夹中。
例如,可以说这些是我的web根目录中唯一的文件和文件夹:
publicDocs/ directorywith_no_defaultfile/ some-legacy-flat-page.htm .htaccess index.php some-legacy-flat-page.htm
我想开始使用Zend MVC的一些较新的网页。
我有一个.htaccess国防部重写规则工作,以便任何请求不存在的文件被发送到由MVC引导文件(/index.php)处理。
使用我目前的设置,以下types的请求被成功路由到“/index.php”,即MVC引导程序:
旧的传统(平面)页面成功地提供以下types的请求
但是,当我请求一个不存在的文件是这样一个目录:
要么
而不是路由到MVC的靴子,我得到一个错误:
Forbidden You don't have permission to access /directorywith_no_defaultfile/ on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
我怀疑这可能与Apache处理默认文件的方式有关。
目前,解决这个问题的唯一方法是:
你知道哪个Apache指令可能导致这个“禁止”的错误?
是否可以在.htaccess中使用任何指令来告诉Apache在目录中丢失默认文件,并将其留给mod重写来担心?
DirectoryIndex指令的文档包括以下内容:
Note that the documents do not need to be relative to the directory; DirectoryIndex index.html index.txt /cgi-bin/index.pl would cause the CGI script /cgi-bin/index.pl to be executed if neither index.html or index.txt existed in a directory.
所以,在适当的地方添加下面的行应该这样做:
DirectoryIndex index.html index.php /index.php
调整这一点,以包括支持任何types的索引文件,你想正常处理。 只要“/index.php”是最后一个,它应该做你想做的。
这是我通常在.htaccess文件中设置我的mod_rewrite脚本
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d rewriterule ^(.*)$ http://www.domain-name.com/$1 [r=301,nc] </IfModule>
希望有所帮助!