事实证明,所有问题都归结为 mod_rewrite 问题。我仍然不是 100% 知道为什么这个问题会出现在一个环境中,但在其他环境中却httpd.conf
没有.htaccess
。RewriteBase
哦,好吧,解决方案是使用指令在关于您的基本 url 的重写规则中明确。
在 API 目录中,我现在有以下.htaccess
文件:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /api
RewriteRule ^$ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
在 API-Explorer 目录中,我现在有以下内容.htaccess
:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /api/explorer
RewriteRule ^$ index.html [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.html [QSA,L]
</IfModule>
为了解决这个问题,我遇到的一个非常宝贵的技巧是打开 Apache 的 mod_rewrite 日志记录。
# Adding logging for Rewrites
RewriteLog logs/rewrite.log
RewriteLogLevel 2
把它放在任何全局范围的区域中httpd.conf
;我把它放在已经存在的关于日志记录的条目周围,但如果你更喜欢它,你也可以把它放在最后。此外,有关重写故障排除的基础知识包括(抱歉,如果这是基本的):
- 确保您的 httpd.conf 已为您服务 Restler 的目录设置
AllowOverride All
并设置。Options FollowSymLinks
- 您可以将所有配置放入
httpd.conf
并完全避免.htaccess
文件(这样也更快一些),但如果您这样做,请记住httpd.conf
绝对 url 引用与.htaccess
' 的相对引用。