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

    描述:使用sed语法过滤输入(请求)和输出(响应)内容
    状态:试验
    模块标识符:sed_module
    源文件:mod_sed.c sed0.c sed1.c regexp.c regexp.h sed.h
    兼容性:可在 Apache 2.3 及更高版本中使用

    摘要

    mod_sed是 in-process 内容过滤器。mod_sed过滤器实现 Solaris 10 sed程序实现的sed编辑命令,如手册页中所述。但是,与sed不同,mod_sed不从标准输入中获取数据。相反,过滤器作用于 client 和服务器之间发送的实体数据。mod_sed可用作输入或输出滤波器。mod_sed是内容过滤器,这意味着它不能用于修改 client 或服务器 http headers。

    mod_sed输出过滤器接受一块数据,对数据执行sed脚本,并生成传递给链中下一个过滤器的输出。

    mod_sed输入过滤器从链中的下一个过滤器读取数据,执行sed脚本,并将生成的数据返回到过滤器链中的调用者过滤器。

    如果在内容中看到换行符,则输入和输出过滤器都只处理数据。在数据的末尾,数据的 rest 被视为最后一行 line。

    Sample Configuration

    添加输出过滤器

    # In the following example, the sed filter will change the string
    # "monday" to "MON" and the string "sunday" to SUN in html documents
    # before sending to the client.
    <Directory "/var/www/docs/sed"> 
        AddOutputFilter Sed html 
        OutputSed "s/monday/MON/g" 
        OutputSed "s/sunday/SUN/g" 
    </Directory>
    

    添加输入过滤器

    # In the following example, the sed filter will change the string
    # "monday" to "MON" and the string "sunday" to SUN in the POST data
    # sent to PHP.
    <Directory "/var/www/docs/sed"> 
        AddInputFilter Sed php 
        InputSed "s/monday/MON/g" 
        InputSed "s/sunday/SUN/g" 
    </Directory>
    

    Sed 命令

    可以从sed 手册页找到sed命令的完整详细信息。

    • b
      分支到指定的标签(类似于 goto)。
    • h
      将当前 line 复制到保持缓冲区。
    • H
      将当前 line 附加到保持缓冲区。
    • g
      将保持缓冲区复制到当前 line。
    • G
      将保持缓冲区附加到当前 line。
    • x
      交换保持缓冲区和当前 line 的内容。

    InputSed 指令

    描述:用于过滤请求数据的 Sed 命令(通常为POST数据)
    句法:InputSed sed-command
    Context:目录,.htaccess
    状态:试验
    模块:mod_sed

    InputSed指令指定要对请求数据 e.g.,POST data 执行的sed命令。

    OutputSed 指令

    描述:用于过滤响应内容的 Sed 命令
    句法:OutputSed sed-command
    Context:目录,.htaccess
    状态:试验
    模块:mod_sed

    OutputSed指令指定要在响应上执行的sed命令。

    上篇:mod_rewrite

    下篇:mod_session