2

我正在开发一个开源项目。我不知道这个项目将安装在最终用户的哪个目录中。我需要向为我的项目创建的 .htaccess 文件添加规则,以便 404 和其他指向我项目根目录中的特定文件。设置脚本在名为“setup”的文件夹中调用,与根文件夹相关,如 root/setup/index.php。

我用来将 404 从根目录中的 .htaccess 引导到 errorcode.php(也在根文件夹中)的路径是:

$installURL = "http://" . $_SERVER['HTTP_HOST'] . dirname($_SERVER['SCRIPT_NAME']);
$save= $installURL;
$str = str_replace( '/setup', '', $save ); //remove /setup/
$installURL= $str ;

然后我打开 .htaccess 文件并制定如下规则:

$fp = fopen("../.htaccess", "a");
fwrite($fp, "\n\n# ErrorDocuments \n");
fwrite($fp, "ErrorDocument 400 ". $installURL."/errorcode.php?error=400 \n");

所有 400 个 HTTP 标头都有一个规则列表。

这对我来说已经工作了大约一个月了。今天,我开始收到服务器错误,日志文件显示以下内容:

[Thu Oct 04 11:56:59 2012] [notice] cannot use a full URL in a 401 ErrorDocument directive --- ignoring!
[Thu Oct 04 11:56:59 2012] [alert] [client 127.0.0.1] C:/wamp/www/Project-BlackHawk/.htaccess: Unsupported HTTP response code 428, referer: http://localhost/Project-BlackHawk/setup/index.php

我的问题是,我是否应该对 ErrorDocument 的路径使用类似的东西:

$installURL = dirname($_SERVER['SCRIPT_NAME']);
$save= $installURL;
$str = str_replace( '/setup', '', $save ); //remove /setup/
$installURL= $str ;
4

1 回答 1

2

听起来您需要从指令中删除该http://localhost部分。ErrorDocument所以$_SERVER['SCRIPT_NAME']可能会为你做,所以会$_SERVER['REQUEST_URI']

于 2012-10-06T04:56:15.130 回答