Spring Cloud RewritePath GatewayFilter工廠

2024-01-05 17:36 更新

RewritePath GatewayFilter工廠采用路徑regexp參數(shù)和replacement參數(shù)。這使用Java正則表達(dá)式提供了一種靈活的方式來重寫請求路徑。

application.yml。 

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

對于/foo/bar的請求路徑,這將在發(fā)出下游請求之前將路徑設(shè)置為/bar。請注意,由于YAML規(guī)范,$\$所取代。

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號