【问题标题】:Wrong reported 404 using by Apache (.htaccess rewrite)Apache 使用错误报告 404(.htaccess 重写)
【发布时间】:2011-08-25 19:27:15
【问题描述】:

我有这个使用 Zend 框架 (PHP) 的 URL http://xxxxxxxxx.com/account/session/login/redirect/%2Fhotel%2Frooms%2Findex%2Fhot_id%2F1。在 .htaccess 的帮助下

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php [NC,L]

问题是我收到了 404 Not found。为了确保它是 Apache,我在 index.php 主文件启动时退出了它,而 apache 仍然报告 404。在退出之前没有执行任何 php 代码。

编辑

我的域的 apache domlog 显示这一行

190.78.208.30 - - [25/Aug/2011:17:48:17 -0430] "GET /account/session/login/redirect/Fhotel%2Frooms%2Findex%2Fhot_id%2F1 HTTP/1.1" 404 25821 "-" "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0"

但error_log中没有关联的行

编辑 2

如果有用,我正在运行 Apache 2.2.19、PHP 5.3.6、cpanel 11.30.2、CentOS 5.6

请注意未找到 404。当我在执行任何其他操作之前退出 index.php 时,404 仍然出现。我可以确定 .htaccess 正在被读取。根据建议,我放了一个

SetEnv MYENV 1

并且出现在同一域中的 phpinfo() 中。我只是仔细检查了我的 access_log 和 error_log 并保持如上所述。

任何想法为什么会发生这种情况?

【问题讨论】:

  • 错误日志应该准确显示 apache 试图为该请求加载的文件/路径。您还可以打开 mod-rewrite 调试以准确查看内容是如何被重写的。
  • 试试这个:RewriteEngine on RewriteRule !.(js|ico|gif|jpg|png|css)$ index.php

标签: php apache zend-framework http-status-code-404


【解决方案1】:

您确定 Apache 正在读取您的 .htaccess 文件吗? 确保通过:

  1. 您有权覆盖网站目录中的值。要拥有这个,你应该在你的 Apache 配置文件中有这样的东西:

    AllowOverride All
    

    目录>

    将 /var/www/html 替换为您网站公共目录的路径

  2. Apache 有权读取您的 .htaccess 文件。

这样 Apache 可以读取和应用您的 .htaccess 文件中的配置。

要对其进行测试,请在您的 .htaccess 文件中设置一个环境变量:

SetEnv MYENV 1

然后使用 index.php 文件中的 phpinfo() 函数并搜索环境变量。如果您的 phpinfo() 输出中不存在环境变量,则意味着 .htaccess 文件未被 Apache 解析。

【讨论】:

    猜你喜欢
    • 2011-07-07
    • 2014-05-12
    • 2023-04-08
    • 1970-01-01
    • 2014-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-26
    相关资源
    最近更新 更多