我也得到了这个,带有一个允许格式化 URL 的 PHP 框架,以便
index.php?controller=doohickey&id=z61
可以改写为
index.php/controller/doohickey/z61
以及框架代码中的正则表达式。
错误看起来像(/var/log/apache/error_log):
GET /index.php/accounts_badoink/confirmaction/WUW%253DWBW%25253DV0tXPWM3Nzc1....
-> 在这种情况下,apache 将文件名解析为
/index.php/accounts_badoink/confirmaction/WUW%253DWBW%25253DV0tXPWM3Nzc1....
(我正在序列化一个对象状态并传递它)。
我必须将它(至少是带有长附加序列化对象的 URL)重写为更习惯的样式:
GET /index.php?controller=accounts_badoink&confirmaction=WUW%253DWBW%25253DV0tXPWM3Nzc1....
-> 在这种情况下,Apache 将文件名解析为index.php
因此,简而言之,尽早重写您的 URL 并包含 ?,以便将数据作为 CGI 样式参数而不是路径元素传递。
我为每个 Apache 进程 ID 运行 strace -p $PID &(由 pidof apache2 报告):
# pidof apache2 | tr ' ' '\n' | grep -v 21561 | sed "s|\(.*\)|strace -p \1 \&|g" | sh -
结束:
# kill -HUP `pidof strace`
看看 apache2 的内核调用:
accept(3, {sa_family=AF_INET, sin_port=htons(38985), sin_addr=inet_addr("127.0.0.1")}, [16]) = 13
fcntl(13, F_GETFD) = 0
fcntl(13, F_SETFD, FD_CLOEXEC) = 0
fcntl(13, F_GETFL) = 0x2 (flags O_RDWR)
fcntl(13, F_SETFL, O_RDWR|O_NONBLOCK) = 0
read(13, "GET /newregcon/index.php/account"..., 8000) = 4949
write(2, "[Wed May 11 15:39:36 2011] [erro"..., 4451) = 4451
writev(13, [{"HTTP/1.1 403 Forbidden\r\nDate: We"..., 219}, {"<!DOCTYPE HTML PUBLIC \"-//IETF//"..., 4610}], 2) = 4829
由于这些系统调用不返回错误(例如 ' ... = -1' ),我下载了 apache2 源代码,发现:
Grep 表示“无法映射”:
server/core.c
3489:AP_DECLARE_NONSTD(int) ap_core_translate(request_rec *r)
3490:{
3520: if ((rv = apr_filepath_merge(&r->filename, conf->ap_document_root, path,
3521: APR_FILEPATH_TRUENAME
3522: | APR_FILEPATH_SECUREROOT, r->pool))
3523: != APR_SUCCESS) {
3524: ap_log_rerror(APLOG_MARK, APLOG_ERR, rv, r,
3525: "Cannot map %s to file", r->the_request);
3526: return HTTP_FORBIDDEN;
3527: }
寻找apr_filepath_merge ...
srclib/apr/file_io/unix/filepath.c
81:APR_DECLARE(apr_status_t) apr_filepath_merge(char **newpath,
82: const char *rootpath,
83: const char *addpath,
84: apr_int32_t flags,
85: apr_pool_t *p)
86:{
87: char *path;
88: apr_size_t rootlen; /* is the length of the src rootpath */
89: apr_size_t maxlen; /* maximum total path length */
149: rootlen = strlen(rootpath);
150: maxlen = rootlen + strlen(addpath) + 4; /* 4 for slashes at start, after
151: * root, and at end, plus trailing
152: * null */
153: if (maxlen > APR_PATH_MAX) {
154: return APR_ENAMETOOLONG;
155: }
找到APR_PATH_MAX ...
网络
./srclib/apr/include/apr.hnw:424:#define APR_PATH_MAX PATH_MAX
WIN32
./srclib/apr/include/apr.hw:584:#define APR_PATH_MAX 8192
./srclib/apr/include/apr.h.in
/* header files for PATH_MAX, _POSIX_PATH_MAX */
#if APR_HAVE_LIMITS_H
#include <limits.h>
/usr/src/linux-headers-2.6.35-28/include/linux/limits.h
#define PATH_MAX 4096 /* # chars in a path name including nul */