RewritePath
GatewayFilter
Factory
“RewritePath” “GatewayFilter” 工厂采用路径 “regexp” 参数和 “replacement” 参数。这使用 Java 正则表达式对请求路径进行灵活改写。以下列表配置了一个 “RewritePath” “GatewayFilter”:
The RewritePath
GatewayFilter
factory takes a path regexp
parameter and a replacement
parameter.
This uses Java regular expressions for a flexible way to rewrite the request path.
The following listing configures a RewritePath
GatewayFilter
:
application.yml
spring:
cloud:
gateway:
routes:
- id: rewritepath_route
uri: https://example.org
predicates:
- Path=/red/**
filters:
- RewritePath=/red/?(?<segment>.*), /$\{segment}
对于请求路径 “/red/blue”,这在发出向下请求之前将路径设置到 “/blue”。请注意,“$” 应替换为 “$\” ,这是由于 YAML 规范。
For a request path of /red/blue
, this sets the path to /blue
before making the downstream request. Note that the $
should be replaced with $\
because of the YAML specification.