我已经使用非常基本的配置在 Apache 2.4.7 上设置了我的虚拟主机:
<VirtualHost *:80>
ServerName foo.example.com
DocumentRoot /var/www/html
DirectoryIndex index.php
FallbackResource /index.php
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
在文档根目录下,我具有以下结构:
/index.php
/help/readme.txt
Run Code Online (Sandbox Code Playgroud)
当我提出请求时,我得到以下结果:
/bla -> 200 OK
/help/ -> 404 Not Found
/help/a -> 200 OK
Run Code Online (Sandbox Code Playgroud)
似乎/help/
目录的存在导致 Apache 返回,404
因为那里没有index.php
,但我希望所有请求都能调用/index.php
并产生200 OK
响应。
我不记得这是使用时的问题mod_rewrite
,但FallbackResource
如果可能的话,我更喜欢使用。有没有办法来解决这个问题?
更新
如果我删除DirectoryIndex
指令,它会起作用,但是会遇到五秒延迟问题。
更新 3
我正在运行以下测试环境;目录结构如下:
./htdocs
index.html
test/
bla.txt
./conf
httpd.conf
./logs
Run Code Online (Sandbox Code Playgroud)
内容httpd.conf
为:
ServerName apache-bug.local
Listen 8085
DirectoryIndex disabled
DirectorySlash Off
<VirtualHost *:8085> …
Run Code Online (Sandbox Code Playgroud)