spring cloud gateway url重写

2022-07-04 12:16:30

将/a/b/c指向到/f/c的控制示例:

spring:
  cloud:
    gateway:
      routes:
      # =====================================
      - id: rewritepath_route
        uri: http://example.org
        predicates:
        - Path=/a/b/**
        filters:
        - RewritePath=/a/b/(?<segment>.*), /f/$\{segment}

参见官方文档

RewritePath GatewayFilter Factory

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.

application.yml.

spring:
  cloud:
    gateway:
      routes:
      # =====================================
      - id: rewritepath_route
        uri: http://example.org
        predicates:
        - Path=/foo/**
        filters:
        - RewritePath=/foo/(?<segment>.*), /$\{segment}

For a request path of /foo/bar, this will set the path to /bar before making the downstream request. Notice the $\ which is replaced with $ because of the YAML spec.

  • 作者:草宝虫
  • 原文链接:https://wanghq.blog.csdn.net/article/details/85336306
    更新时间:2022-07-04 12:16:30