“目录索引被选项指令禁止”可能是导致“请求超出 10 个内部重定向的限制”的原因吗?

“目录索引被选项指令禁止”可能是导致“请求超出 10 个内部重定向的限制”的原因吗?

我正在尝试在本地环境中设置一个项目,以便能够对其进行操作。使用的是 PHP 5.3.3 和 Apache 2.2.15 以及 CodeIgniter 2.3.1(PHP 和 CI 版本与此无关,仅供参考,以防万一)。

我已经设置了一个 VH,如下所示:

<VirtualHost *:80>
    DocumentRoot "/var/www/html/document_api/public"
    ServerName document.api.localhost    
    <Directory "/var/www/html/document_api/public">
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>

    LogLevel debug
</VirtualHost>

项目/var/www/html/document_api/public/.htaccess文件如下:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /

#Rule 2: IF a file exists when .php is added, then rewrite URL by adding .php
RewriteRule ^([0-9A-_Za-z]+)$ $1.php [L]

RewriteCond %{REQUEST_FILENAME}.php !-f
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

当我尝试访问该 URL 时,document.api.localhost:8080出现了以下错误:

[Mon Jan 22 17:25:50 2018] [error] [client 10.0.2.2] Directory index forbidden by Options directive: /var/www/html/document_api/public/
[Mon Jan 22 17:25:50 2018] [error] [client 10.0.2.2] File does not exist: /var/www/error
[Mon Jan 22 17:25:51 2018] [error] [client 10.0.2.2] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://document.api.localhost:8080/
[Mon Jan 22 17:25:51 2018] [debug] core.c(3112): [client 10.0.2.2] r->uri = /index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/favicon.ico, referer: http://document.api.localhost:8080/
[Mon Jan 22 17:25:51 2018] [debug] core.c(3118): [client 10.0.2.2] redirected from r->uri = /index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/favicon.ico, referer: http://document.api.localhost:8080/
[Mon Jan 22 17:25:51 2018] [debug] core.c(3118): [client 10.0.2.2] redirected from r->uri = /index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/favicon.ico, referer: http://document.api.localhost:8080/
[Mon Jan 22 17:25:51 2018] [debug] core.c(3118): [client 10.0.2.2] redirected from r->uri = /index.php/index.php/index.php/index.php/index.php/index.php/index.php/favicon.ico, referer: http://document.api.localhost:8080/
[Mon Jan 22 17:25:51 2018] [debug] core.c(3118): [client 10.0.2.2] redirected from r->uri = /index.php/index.php/index.php/index.php/index.php/index.php/favicon.ico, referer: http://document.api.localhost:8080/ [Mon Jan 22 17:25:51 2018] [debug] core.c(3118): [client 10.0.2.2] redirected from r->uri = /index.php/index.php/index.php/index.php/index.php/favicon.ico, referer: http://document.api.localhost:8080/
[Mon Jan 22 17:25:51 2018] [debug] core.c(3118): [client 10.0.2.2] redirected from r->uri = /index.php/index.php/index.php/index.php/favicon.ico, referer: http://document.api.localhost:8080/
[Mon Jan 22 17:25:51 2018] [debug] core.c(3118): [client 10.0.2.2] redirected from r->uri = /index.php/index.php/index.php/favicon.ico, referer: http://document.api.localhost:8080/
[Mon Jan 22 17:25:51 2018] [debug] core.c(3118): [client 10.0.2.2] redirected from r->uri = /index.php/index.php/favicon.ico, referer: http://document.api.localhost:8080/
[Mon Jan 22 17:25:51 2018] [debug] core.c(3118): [client 10.0.2.2] redirected from r->uri = /index.php/favicon.ico, referer: http://document.api.localhost:8080/
[Mon Jan 22 17:25:51 2018] [debug] core.c(3118): [client 10.0.2.2] redirected from r->uri = /favicon.ico, referer: http://document.api.localhost:8080/

我是不是漏掉了什么?这个设置有什么问题?

答案1

您的日志文件中有两个问题。首先,目录索引被禁止,这是由

RewriteCond %{REQUEST_FILENAME} !-d

请求的路径显然是一个目录,它就是DocumentRoot目录。因此跳过重定向到 PHP 的规则。你可能没有,index.php因为你的DirectoryIndex和目录列表是被禁止的(文档)。

第二个问题,无休止的重定向,是由另一个请求引起的,这次浏览器请求favicon.ico。该文件不存在,并被重写为index.php/favicon.ico,但不存在这样的文件或文件夹,它被重写为 ,index.php/index.php/favicon.ico依此类推。

您可能应该跳过重定向index.php/something并将其更改为 GET 参数,我看不出您尝试以这种方式重定向的任何理由。/index.php?path=something会更有意义。

相关内容