• 首页
  • vue
  • TypeScript
  • JavaScript
  • scss
  • css3
  • html5
  • php
  • MySQL
  • redis
  • jQuery
  • mod_dir

    描述:提供“尾部斜杠”重定向和服务目录索引 files
    状态:Base
    模块标识符:dir_module
    源文件:mod_dir.c

    摘要

    目录索引可以来自以下两个来源之一:

    • 用户编写的文件,通常称为index.html。DirectoryIndex指令设置此文件的 name。这由mod_dir控制。
    • 否则,由服务器生成的列表。这由mod_autoindex提供。

    这两个函数是分开的,因此您可以根据需要完全删除(或替换)自动索引生成。

    当服务器收到 URL http://servername/foo/dirname的请求时,会发出“尾部斜杠”重定向,其中dirname是目录。目录需要尾部斜杠,因此mod_dir会发出重定向到http://servername/foo/dirname/

    DirectoryCheckHandler 指令

    描述:切换配置另一个处理程序时此模块如何响应
    句法:DirectoryCheckHandler On\|Off
    默认:DirectoryCheckHandler Off
    Context:server config,virtual host,directory,.htaccess
    覆盖:索引
    状态:Base
    模块:mod_dir
    兼容性:可在 2.4.8 及更高版本中使用。 2.4 之前的版本隐式执行,就像指定了“DirectoryCheckHandler ON”一样。

    DirectoryCheckHandler指令确定mod_dir是否应检查目录索引,或者在为当前 URL 配置了其他处理程序时添加尾部斜杠。处理程序可以通过指令(如SetHandler)或其他模块(如 per-directory 替换期间的mod_rewrite)进行设置。

    在 2.4 之前的版本中,如果为 URL 配置了任何其他处理程序,则此模块不会执行任何操作。即使为整个目录指定了SetHandler指令,这也允许提供目录索引,但它也可能导致与诸如mod_rewrite之类的模块发生某些冲突。

    DirectoryIndex 指令

    描述:client 请求目录时要查找的资源列表
    句法:DirectoryIndex disabled \| local-url[local-url]...
    默认:DirectoryIndex index.html
    Context:server config,virtual host,directory,.htaccess
    覆盖:索引
    状态:Base
    模块:mod_dir

    当 client 通过在目录 name 的末尾指定/来请求目录的索引时,DirectoryIndex指令设置要查找的资源列表。 Local-url 是服务器上相对于请求目录的文档的(%-encoded)URL;它通常是目录中文件的 name。可以给出几个 URL,在这种情况下,服务器将_return 它找到的第一个 URL。如果存在 none 资源且设置了Indexes选项,则服务器将生成自己的目录列表。

    DirectoryIndex index.html
    

    那么http://example.com/docs/的请求会_ret如果它存在,或者如果没有则列出目录。

    请注意,文档不需要相对于目录;

    DirectoryIndex index.html index.txt  /cgi-bin/index.pl
    

    如果目录中既不存在index.htmlindex.txt,则会导致执行 CGI 脚本/cgi-bin/index.pl

    “禁用”的单个参数会阻止mod_dir搜索索引。如果“禁用”的参数在其之前或之后具有任何 arguments,即使它们也被“禁用”,也将按字面解释。

    注意:相同的 context中的多个DirectoryIndex指令将添加到要查找的资源列表而不是替换:

    # Example A: Set index.html as an index page, then add index.php to that list as well.
    <Directory "/foo">
        DirectoryIndex index.html
        DirectoryIndex index.php
    </Directory>
    
    # Example B: This is identical to example A, except it's done with a single directive.
    <Directory "/foo">
        DirectoryIndex index.html index.php
    </Directory>
    
    # Example C: To replace the list, you must explicitly reset it first:
    # In this example, only index.php will remain as an index resource.
    <Directory "/foo">
        DirectoryIndex index.html
        DirectoryIndex disabled
        DirectoryIndex index.php
    </Directory>
    

    DirectoryIndexRedirect 指令

    描述:配置目录索引的外部重定向。
    句法:DirectoryIndexRedirect on \| off \| permanent \| temp \| seeother \| 3xx-code
    默认:DirectoryIndexRedirect off
    Context:server config,virtual host,directory,.htaccess
    覆盖:索引
    状态:Base
    模块:mod_dir
    兼容性:可在 version 2.3.14 及更高版本中使用

    默认情况下,选择DirectoryIndex并透明地返回到 client。DirectoryIndexRedirect会导致发出外部重定向。

    争论可以是:

    • on:向索引资源发出 302 重定向。
    • off:不发出重定向。这是 mod_dir 的 legacy 行为。
    • permanent:向索引资源发出 301(永久)重定向。
    • temp:这与on具有相同的效果
    • seeother:向索引资源发出 303 重定向(也称为“See Other”)。
    • xx-code:发出由所选 3xx code 标记的重定向。

    DirectoryIndexRedirect on
    

    http://example.com/docs/的请求会临时重定向到http://example.com/docs/index.html(如果存在)。

    DirectorySlash 指令

    描述:打开或关闭尾随斜杠重定向
    句法:DirectorySlash On\|Off
    默认:DirectorySlash On
    Context:server config,virtual host,directory,.htaccess
    覆盖:索引
    状态:Base
    模块:mod_dir

    DirectorySlash指令确定mod_dir是否应该修复指向目录的 URL。

    通常,如果用户请求的资源没有指向目录的尾部斜杠,mod_dir会将其重定向到相同的资源,但由于某些原因,使用尾部斜杠:

    • 用户最终请求资源的规范 URL
    • mod_autoindex正常工作。由于它不会在链接中发出路径,因此会指向错误的路径。
    • 仅对使用尾部斜杠请求的目录评估DirectoryIndex。
    • html 页面内的相对 URL references 将正常工作。

    如果您不希望此效果并且上述原因不适用于您,则可以关闭重定向,如下所示。但请注意,执行此操作可能会产生安全隐患。

    # see security warning below!
    <Location "/some/path">
        DirectorySlash Off
        SetHandler some-handler
    </Location>
    

    安全警告

    关闭尾部斜杠重定向可能会导致信息泄露。考虑一种情况,其中mod_autoindex是 active(Options +Indexes)并且DirectoryIndex设置为有效资源(例如,index.html),并且没有为该 URL 定义其他特殊处理程序。在这种情况下,带有斜杠的请求将显示index.html文件。但是没有斜杠的请求会列出目录内容

    另请注意,某些浏览器可能会在发出重定向时错误地将 POST 请求更改为 GET(从而丢弃 POST 数据)。

    FallbackResource 指令

    描述:为未 map 到文件的请求定义默认 URL
    句法:FallbackResource disabled \| local-url
    默认:disabled - httpd will return 404(Not Found)
    Context:server config,virtual host,directory,.htaccess
    覆盖:索引
    状态:Base
    模块:mod_dir
    兼容性:参数在 version 2.4.4 及更高版本中可用

    使用此选项可以为任何未映射到文件系统中任何内容的 URL 设置处理程序,否则将 return HTTP 404(Not Found)。例如

    FallbackResource /not-404.php
    

    将导致 non-existent files 的请求由not-404.php处理,而对存在的 files 的请求不受影响。

    通常希望让单个文件或资源处理对特定目录的所有请求,除了那些对应于现有文件或脚本的请求。这通常被称为“前端控制器”。

    在早期版本的 httpd 中,此效果通常需要mod_rewrite,并且使用-f-d测试存在文件和目录。现在只需要一个 line 的 line 配置。

    FallbackResource /index.php
    

    现有的 files,例如 images,css files 等,将正常提供。

    如果不需要从 parent 目录继承,请使用disabled参数禁用该 feature。

    在 sub-URI 中,例如 http://example.com/blog/,sub-URI 必须以 local-url 形式提供:

    <Directory "/web/example.com/htdocs/blog">
        FallbackResource /blog/index.php
    </Directory>
    <Directory "/web/example.com/htdocs/blog/images">
        FallbackResource disabled
    </Directory>
    

    上篇:mod_dialup

    下篇:mod_dumpio