我正在尝试在我的本地环境中设置一个项目,以便我能够处理它。正在使用 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/
我在这里错过了什么吗?这个设置有什么问题?
您的日志文件中有两个问题。首先是目录索引被禁止,这是由于
请求的路径显然是一个目录,它是
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
会更有意义。