docs/en/docs/rules/replaceStatus.md
The replaceStatus protocol is used to replace HTTP status codes. It changes the original status code to a specified HTTP status code after the request response is completed. Through the replaceStatus protocol, you can:
The replaceStatus protocol supports multiple configuration methods:
Write the status code to replace directly in the rule.
pattern replaceStatus://code [lineProps...] [filters...]
Example:
www.example.com/api/old replaceStatus://301
Use this method when you need to return different status codes based on conditions or want to reuse configurations.
pattern replaceStatus://{custom-key} [lineProps...] [filters...]
``` custom-key
404
```
Reference a status code pre-defined in the Values panel (central configuration area).
pattern replaceStatus://{key-of-values} [lineProps...] [filters...]
Prerequisite: A key named key-of-values with a status code as its value must exist in Values.
Currently NOT supported to dynamically load content from local files or remote URLs.
| Parameter | Required | Description & Examples |
|---|---|---|
| pattern | Yes | Expression used to match the request URL. |
| • Supports domains, paths, wildcards, regular expressions. | ||
| • See Matching Pattern Documentation for details. | ||
| code | Yes | The HTTP response status code to replace, such as: |
• 200 OK | ||
• 301 Permanent Redirect | ||
• 302 Temporary Redirect | ||
• 404 Not Found | ||
• 500 Internal Server Error | ||
| • Supports all standard HTTP status codes. | ||
| lineProps | No | Sets additional properties for the rule. |
• Example: lineProps://important can increase this rule's priority. | ||
| • See lineProps Documentation for details. | ||
| filters | No | Optional filter conditions for precise control over when the rule takes effect. |
| • Can match request URL, method, headers, body content. | ||
| • Can match response status code, headers. | ||
| • See Filters Documentation for details. |
# Replace any response with 404 status code.
www.example.com replaceStatus://404
# Replace server errors with normal status codes.
www.example.com/api replaceStatus://200 includeFilter://s:500
# Modify redirect status codes.
www.example.com/redirect replaceStatus://307
# Replace normal responses with 401 status code, triggering browser authentication popup.
www.example.com/secure-page replaceStatus://401
# Disable the login dialog and directly return 401.
www.example.com/secure-page replaceStatus://401 disable://userLogin
# Or use lineProps to achieve the same effect.
www.example.com/secure-page replaceStatus://401 lineProps://disableUserLogin
# Replace only when the original status code is 200 with 500.
www.example.com/api replaceStatus://500 includeFilter://s:200
# Replace response status codes only for specific paths.
www.example.com/api/admin replaceStatus://403
# Replace status code and modify response content.
www.example.com/api/error replaceStatus://500 resBody://{errMsg}
``` errMsg
{"message":"Custom error message"}
```
# Replace with 301 redirect and set new Location header.
www.example.com/old-url replaceStatus://301 resHeaders://location=https://www.example.com/new-url
``` maintenance-status
503
```
# Replace all website responses with maintenance status.
www.example.com replaceStatus://{maintenance-status}
# Simulate errors only in testing environment.
test.example.com/api replaceStatus://500
# Development environment remains unchanged.
# dev.example.com/api (no replaceStatus set)
# Test client handling of server errors.
www.example.com/api replaceStatus://500 includeFilter://chance:0.1
# Test permanent redirect caching.
www.example.com/old-page replaceStatus://301
# Test temporary redirect.
www.example.com/temp-redirect replaceStatus://302
# Test unauthenticated access.
www.example.com/protected replaceStatus://401
# Test insufficient permissions.
www.example.com/admin replaceStatus://403
# Test too many requests scenarios.
www.example.com/api/rate-limited replaceStatus://429 resHeaders://retry-after=60
# Test maintenance page.
www.example.com replaceStatus://503 resBody://(<h1>System Under Maintenance...</h1>)
The main distinction between the replaceStatus protocol and the statusCode protocol lies in the processing timing:
replaceStatus: First requests the backend server, then replaces the status code after receiving the response.statusCode: Does not request the backend server, immediately returns the specified status code.replaceStatus takes effect during the response stage, statusCode takes effect during the request stage.replaceStatus accesses the server, statusCode does not.replaceStatus when real server data is needed, use statusCode for complete simulation.resBody protocol.401 status code, the browser authentication popup is triggered by default.disable://userLogin.lineProps://disableUserLogin.enable protocol.Location response header accordingly.# Unify all redirects as 302.
www.example.com replaceStatus://302 includeFilter://s:301
# Replace responses with errors 10% of the time.
www.example.com/api replaceStatus://500 includeFilter://chance:0.1
# Perform different replacements for different original status codes.
www.example.com/api replaceStatus://200 includeFilter://s:404
www.example.com/api replaceStatus://400 includeFilter://s:403
A: Check:
A: Check:
A: For 401 status code:
disable://userLogin or lineProps://disableUserLogin is added.A: Check:
Location header is set.