【发布时间】:2012-03-23 19:24:56
【问题描述】:
我正在使用 Luracast Restler 库开发一个 API。我正在寻找的只是将 index.php 从我的 URL 中“隐藏”起来,以符合 RESTful API 标准。注意!:是的,我启用了 mod_rewrite,是的,我在目录中有 .htaccess 文件。在我的机器上完成这项工作完全没有问题,但是当将其移至生产环境进行一些基本测试时,.htaccess 文件的行为似乎有所不同,因为 URL 中再次需要 index.php!
我的开发机器和生产机器都在运行 Windows。两者都使用多个虚拟主机。两者都启用了 mod_rewrite。
我的 .htaccess 文件实际上就是提供的示例:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
<IfModule mod_php5.c>
php_flag display_errors Off
</IfModule>
我们在 httpd.conf 中有相同的目录设置:
<directory "C:\www">
Options FollowSymLinks -Includes -ExecCGI -Indexes -SymLinksIfOwnerMatch
order allow,deny
Allow from all
AllowOverride All
</directory>
而且这种配置在我的开发机器上运行良好。当我将其移至生产环境时,它需要 URL 中的 index.php 才能将请求提供给我的 index.php 文件。如果我从 URL 中删除 index.php,我会从 Apache 得到 404(不是 Restler 响应)。我也在 Apache 日志中收到此错误:
File does not exist: C:/www/api_website_com/public/classname/function
据我了解,这个 .htaccess 应该将我的 HTTP 请求直接重写为 index.php,而不是像文件一样查找 URL。有人有想法吗?它必须是我忽略的一些简单的东西。
另外请注意,我无法启用 RewriteLog,因为我无权访问生产服务器的 httpd.conf。
【问题讨论】:
-
This thread 在 Luracast Restler 问题页面中可能会有所启发。看看吧!
-
不幸的是,这些都无法解决问题。似乎将所有请求都指向 index.php 的重写没有正确地重写请求 - Apache 仍在寻找实际的文件路径。
-
已解决。显然,有人在 httpd.conf 中添加了以下行 - "AccessFileName htaccess.txt" .... 哇.... 抱歉这个愚蠢的问题。
标签: apache mod-rewrite