关于请求路径重写

6.16. The 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. The following listing configures a RewritePathGatewayFilter:

Example 41. application.yml

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

  

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.

修改“admin_route”路由规则:

        - id: admin_route
          uri: lb://renren-fast
          predicates:
            - Path=/api/**
          filters:
            - RewritePath=/api/(?<segment>/?.*), /renren-fast/${segment}

  再次访问:http://localhost:8001/#/login,验证码能够正常的加载了。

原文地址:https://www.cnblogs.com/vincentmax/p/14381789.html