apache2的含义CONTEXT_DOCUMENT_ROOT和CONTEXT_PREFIX? [英] Meaning of apache2 CONTEXT_DOCUMENT_ROOT and CONTEXT_PREFIX?

查看:251
本文介绍了apache2的含义CONTEXT_DOCUMENT_ROOT和CONTEXT_PREFIX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何定义Apache2(2.4)CGI环境变量 CONTEXT_DOCUMENT_ROOT CONTEXT_PREFIX

How are the Apache2 (2.4) CGI environment variables CONTEXT_DOCUMENT_ROOT and CONTEXT_PREFIX defined?

根据实验,我确定了以下内容:

From experimentation, I've determined the following:


  • <$ c当 DirectoryIndex ErrorDocument <时,$ c> CONTEXT_DOCUMENT_ROOT 似乎是原始请求的完整本地路径。 / code>调用CGI脚本。

  • CONTEXT_DOCUMENT_ROOT appears to be the full local path to the original request when DirectoryIndex or ErrorDocument call a CGI script.

CONTEXT_PREFIX DirectoryIndex ErrorDocument REQUEST_URI ,没有任何查询部分。 code>调用了CGI脚本。 (在这些情况下, REQUEST_URI 设置为CGI脚本的URI,而不是原始的URI。)

CONTEXT_PREFIX appears to be the original REQUEST_URI, sans any query part, when DirectoryIndex or ErrorDocument have called a CGI script. (In these cases, REQUEST_URI is set to the URI of the CGI script, rather than the original.)

但是,我似乎找不到来自Apache的有关这些变量的任何官方文档。

However, I can't seem to find any official documentation from Apache on these variables. Does anyone here have a link to such documentation, or more authoritative knowledge to share?

推荐答案

CONTEXT_PREFIX CONTEXT_DOCUMENT_ROOT 告诉您apache如何使用 Alias 指令(或类似功能-如 mod_userdir )将URL路径转换为文件系统路径。文件系统路径最终指向要提供的文件或要运行的cgi脚本。

CONTEXT_PREFIX and CONTEXT_DOCUMENT_ROOT tell you how apache used an Alias directive (or similar feature - like mod_userdir) to translate the URL path to the file system path. The file system path will end up pointing to the the file to be served or a cgi script to run.

因此,如果apache转换了URL:

So, if apache translates the URL:

    http://host/_CONTEXT_PREFIX/path/file

到文件系统路径:

    /_CONTEXT_DOCUMENT_ROOT/path/file

这表示存在别名(或 ScriptAlias 或类似的机制,例如 mod_userdir ),如下所示:

it implies there is an Alias (or ScriptAlias or similar mechanism such as mod_userdir) like the following:

    Alias /_CONTEXT_PREFIX /_CONTEXT_DOCUMENT_ROOT

别名指令将 / _ CONTENT_PREFIX 保存在 $ {CONTEXT_PREFIX} 中,而 / _ CONTEXT_DOCUMENT_ROOT 保存在 $ {CONTEXT_DOCUMENT_ROOT}

The Alias directive saves /_CONTENT_PREFIX in ${CONTEXT_PREFIX} and /_CONTEXT_DOCUMENT_ROOT is saved in ${CONTEXT_DOCUMENT_ROOT}.

这里是使用它的一个示例。在< Directory> 上下文中, RewriteRule 将相对于目录的路径名转换为绝对URL路径,或者将绝对文件名(必须存在)。因此,如果您想将以.htm结尾的URL转换为.php,则必须这样写:

Here is one example of using it. In a <Directory> context RewriteRule translates a path name relative to the directory to a absolute URL path, or an absolute file name (which must exist). So if you wanted to translate URL's that ended in .htm to .php, you would have to write it like this:

    <Directory "/_CONTEXT_DOCMENT_ROOT">
        <FilesMatch "*.htm">
            RewriteEngine On
            RewriteRule (.*)[.]html$ /_CONTEXT_DOCUMENT_ROOT/$1.php
        </FilesMatch>
    </Directory>

现在,您无需重复 / _ CONTEXT_DOCUMENT_ROOT ,但也许更重要的是文件不必存在,因为我们将其重写为URL路径:

Now you can write it without repeating /_CONTEXT_DOCUMENT_ROOT, but perhaps more importantly the file does not have to exist because we are rewriting it to a URL path:

    <Directory "/_CONTEXT_DOCMENT_ROOT">
        <FilesMatch *.htm>
            RewriteEngine On
            RewriteRule (.*)[.].* ${CONTEXT_PREFIX}/$1.php
        </FilesMatch>
    </Directory>

这篇关于apache2的含义CONTEXT_DOCUMENT_ROOT和CONTEXT_PREFIX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆