3

在我的本地开发机器上,我下载了 PDT + Zend Server,其中包括在 Windows 7 上运行的 Apache 2.2.16 和 PHP 5.3.5。在我的本地站点上,我包括了一个 .htaccess,其中包含 404、403 和 500 的 ErrorDocuments . 在我的 PHP 中,当用户请求一个不存在的文档时,我使用 header("Http/1.0 404 Not Found")。在我的本地服务器上,一切正常。我的自定义 ErrorDocument 出现了,我很高兴。

我将所有内容上传到我在 Linux 服务器上运行 Apache 2.2.38 和 PHP 5.3.8 的共享主机,突然间,ErrorDocuments 仅在它们不是来自 PHP 时才起作用。

PHP.ini 或 httpd.conf 或 .htaccess 中是否有一些设置允许 Apace 查看来自 PHP 的错误代码,这使我的开发服务器正常工作,但不是我的共享主机?

在研究这一点时,我所看到的只是“一旦它传递给 PHP,Apache 就看不到状态码”。在这种情况下,为什么我的开发服务器可以正常工作?

编辑

为清楚起见,这里是 .htaccess:

# Use PHP 5.3
Action application/x-hg-php53 /cgi-sys/php53
AddHandler application/x-hg-php53 .php 

#Deny Include Files
<Files *.inc>
order deny,allow
deny from all
</files>

#Provide custom error documents
ErrorDocument 404 /Errors/Http404.php
ErrorDocument 403 /Errors/Http403.php
ErrorDocument 500 /Errors/Http500.php

.htaccess有效,因为如果用户导航到 myhost.com/jdkslfjdls,用户会收到 Errors/Http404.php 的内容。

但是,如果用户导航到 myhost.com/images/GetImage.php?Id=5(当没有图像 #5 时),则用户不会收到任何内容。

如果他们导航到(内部 IP 地址)/images/GetImage.php?Id=5,用户会收到 Errors/Http404.php 的内容。

如果用户尝试访问 GetImage.php?Id=6(当有图像 #6 但他们没有权限时),也会出现类似的问题。在共享服务器上,他们得到一个空白页面或浏览器的 403 错误。在我的开发服务器上,他们得到了我实际的自定义 403 错误页面。

同样,如果我尝试访问 .inc 文件,则 403 错误文档适用于共享服务器。

4

2 回答 2

0

Are you sure that your .htaccess file is used on the server? Sometimes the hosting company does not allow the global apache settings to be overwritten by the local .htaccess files.

If you however have access to your virtualhost configuration than you may want to look at the following directive

AllowOverride All

If instead you find

AllowOverride None

try to change as above.

于 2011-09-16T15:57:55.377 回答
0

检查你是否有

AllowOverride ALL

在与您的网站相对应的 VirtualHost 内的 Directory 指令下的 apache.conf 中

无论如何,这可能是一个可能的原因,另一个可能是检查您是否启用了 mod_rewrite

在基于 ubuntu 或 debian 的系统上,您只需将 mod_rewrite.load 从 /etc/apache2/mods-available/mod_rewrite.load 链接或复制到 /etc/apache2/mods-enabled/mod_rewrite.load

重写应该无关紧要,但我见过你的 .htaccess 指令可能需要 mod_rewrite 的情况

因此,请检查 apache conf 文件中的这些内容。如果没有任何反应,请联系我@phpcip@gmail.com

希望它有效。

于 2011-09-16T16:25:53.440 回答