RedirectTo
フィルター
RedirectTo
フィルターは、status
および url
という 2 つのパラメーターを取ります。status
パラメーターは、301 などの 300 シリーズリダイレクト HTTP コードである必要があります。url
パラメーターは有効な URL である必要があります。これは、Location
ヘッダーの値です。相対リダイレクトの場合は、ルート定義の URI として uri: no://op
を使用する必要があります。次のリストは、RedirectTo
フィルターを構成します。
application.yml
spring:
cloud:
gateway:
mvc:
routes:
- id: redirectto_route
uri: https://example.org
filters:
- RedirectTo=302, https://acme.org
GatewaySampleApplication.java
import static org.springframework.cloud.gateway.server.mvc.filter.FilterFunctions.redirectTo;
import static org.springframework.cloud.gateway.server.mvc.handler.GatewayRouterFunctions.route;
import static org.springframework.cloud.gateway.server.mvc.handler.HandlerFunctions.http;
@Configuration
class RouteConfiguration {
@Bean
public RouterFunction<ServerResponse> gatewayRouterFunctionsRedirectTo() {
return route("redirectto_route")
.GET("/**", http("https://example.org"))
.filter(redirectTo(302, URI.create("acme.org")))
.build();
}
}
これにより、Location:https://acme.org
ヘッダー付きのステータス 302 が送信され、リダイレクトが実行されます。