> For the complete documentation index, see [llms.txt](https://www.axisnow.io/zh/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.axisnow.io/zh/docs/edge/policies/request-processing.md).

# 请求处理

在边缘完成 URL 重定向与直接应答

请求处理插件让边缘直接应答一部分请求而不回源：URL 重定向把客户端引导到新地址，边缘响应返回设定的内容。两者都在[认证与授权](/zh/docs/edge/policies/authn-authz.md)之后、[通用访问控制](/zh/docs/edge/policies/access-control.md)与[速率控制](/zh/docs/edge/policies/rate-limiting.md)之前执行，命中即结束请求。

## 两个动作 <a href="#actions" id="actions"></a>

<table data-search="false"><thead><tr><th width="140">动作</th><th>典型用途</th></tr></thead><tbody><tr><td><a href="#redirect">URL 重定向</a></td><td>域名与路径迁移、根域名跳转到 www、按访客所在地区分流</td></tr><tr><td>边缘响应</td><td>维护页、固定内容的文件</td></tr></tbody></table>

它是[多动作配置类插件](/zh/docs/edge/policies/rules.md#rulesets)，没有默认规则。两个动作都取到配置时先执行 URL 重定向，未给出跳转（通配符不匹配、脚本返回 `nil` 或出错）时执行边缘响应。执行了跳转或边缘响应的请求不再进入通用访问控制、速率控制和缓存控制，边缘响应也不进入边缘缓存。

## URL 重定向 <a href="#redirect" id="redirect"></a>

条件命中即取走本动作：通配符不匹配、脚本返回 `nil` 的请求不再匹配后面的 URL 重定向规则，条件至少限定 Host 和路径。四种方式对原查询串的处理不同：

<table data-search="false"><thead><tr><th width="140">方式</th><th width="200">原查询串</th><th>说明</th></tr></thead><tbody><tr><td>静态 URL</td><td>不携带</td><td>目标可以是绝对 URL 或以 <code>/</code> 开头的站内路径</td></tr><tr><td>动态构建</td><td>留空即沿用，不能去掉</td><td><code>${{http.host}}</code> 不含端口，要保留端口用 <code>${{http.request.headers["host"]}}</code>；查询串可把固定参数与 <code>${{http.request.uri.query}}</code> 合并，合并后重新编码，参数顺序可能变化</td></tr><tr><td>通配符匹配</td><td>由开关决定</td><td>匹配对象是 <code>协议://Host/路径</code>，不含查询串，不区分大小写，<code>*</code> 可匹配空串；<code>http*://www.example.com/*</code> 同时匹配 HTTP 和 HTTPS，此时 <code>${1}</code> 是 <code>s</code> 或空串，路径从 <code>${2}</code> 起</td></tr><tr><td>自定义脚本</td><td>脚本自行拼接</td><td>状态码取动作配置，脚本不能改；运行出错按不跳转处理，请求照常回源，控制台不提示。<code>ctx</code> 成员与示例见<a href="/zh/docs/edge/policies/edge-runtime.md">边缘运行时</a></td></tr></tbody></table>

状态码的客户端行为：

<table data-search="false"><thead><tr><th width="220">状态码</th><th>客户端行为</th></tr></thead><tbody><tr><td>301 Moved Permanently</td><td>浏览器缓存，之后不再请求原地址；POST 可能被改为 GET</td></tr><tr><td>302 Found</td><td>不缓存；POST 可能被改为 GET</td></tr><tr><td>303 See Other</td><td>一律以 GET 访问目标，用于 POST 之后跳到结果页</td></tr><tr><td>307 Temporary Redirect</td><td>不缓存；保留原方法和请求体</td></tr><tr><td>308 Permanent Redirect</td><td>浏览器缓存；保留原方法和请求体</td></tr></tbody></table>

效果预览只替换变量，不求值规则条件；循环提示按目标与示例的协议、Host、路径是否相同判断，不比较查询串。

## 边界 <a href="#boundaries" id="boundaries"></a>

<table data-search="false"><thead><tr><th width="260">功能</th><th>配置位置</th></tr></thead><tbody><tr><td>HTTP 跳转到 HTTPS</td><td><a href="/zh/docs/edge/policies/ssl-tls/configuration.md#force-https">SSL/TLS › 强制 HTTPS</a></td></tr><tr><td>按安全策略拒绝请求并返回页面</td><td><a href="/zh/docs/edge/policies/access-control.md">通用访问控制</a>、<a href="/zh/docs/edge/policies/rate-limiting.md">速率控制</a>的阻断动作，可配合 IP 封禁与挑战</td></tr><tr><td>替换源站返回的错误页</td><td>响应控制插件的自定义错误页面</td></tr><tr><td>改写回源地址而不改变客户端看到的地址</td><td><a href="/zh/docs/edge/policies/upstream-control/configuration.md#url-rewrite">回源控制 › URL 改写</a></td></tr></tbody></table>

## 最佳实践 <a href="#best-practices" id="best-practices"></a>

* **先用临时跳转验证**：301 Moved Permanently 和 308 Permanent Redirect 被浏览器长期缓存，写错后用户侧难以撤销。新规则先用 302 Found 上线，确认后再改为永久跳转。
* **表单和接口用保留方法的状态码**：301、302 下客户端可能把 POST 改为 GET 并丢弃请求体；目标会收到 POST、PUT 时用 307 Temporary Redirect 或 308。
* **维护页用 503 并给 Retry-After**：搜索引擎把 503 Service Unavailable 视为临时不可用，不移除收录。开启响应体时 `Retry-After` 已预置，再加预设 `Cache-Control: no-store`，避免浏览器和中间缓存留住维护页。
* **边缘响应不替代阻断**：拒绝可疑来源用通用访问控制的阻断，有洞察、IP 封禁和挑战配合；边缘响应命中的请求不经过这些插件，也不计入限速。

## 下一步 <a href="#next-steps" id="next-steps"></a>

<table data-search="false"><thead><tr><th width="160">页面</th><th>内容</th></tr></thead><tbody><tr><td><a href="/zh/docs/edge/policies/request-processing/use-cases.md">配置场景</a></td><td>可直接套用的规则</td></tr><tr><td><a href="/zh/docs/edge/policies/request-processing/faq.md">常见问题</a></td><td>循环、浏览器缓存的跳转、参数丢失、通配符不命中的排查</td></tr></tbody></table>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.axisnow.io/zh/docs/edge/policies/request-processing.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
