假设有两个设计页面,一个页面名为mobile.html
,另一个页面为desktop.html
,
在UrlRewrite
下方,我可以将用户重定向到mobile.html
<rewrite>
<rules>
<rule name="MobileRedirect" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_USER_AGENT}" pattern="midp|mobile|phone|android|iphone|ipad" />
</conditions>
<action type="Redirect" url="/mobile.html" />
</rule>
</rules>
</rewrite>
但是它被困在太多请求中
您的网站将您重定向了太多次。
很明显,正是由于该rule
,它可以毫无问题地重定向到mobile.html
,但是通过使mobile.html
再次执行该操作,它将在循环重定向中删除。
同样通过添加<add input="{url}" negate="true" pattern="mobile.html"/>
也不起作用。
答案 0 :(得分:0)
您可以尝试以下方法。添加另一个条件,该条件不包含mobile.html网址。
@Override
public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
return chain.filter(exchange).then(Mono.defer(() -> {
if (HttpStatus.NOT_FOUND.equals(exchange.getResponse().getStatusCode())) {
return chain.filter(exchange.mutate().request(exchange.getRequest().mutate().path("/index.html").build()).build());
}
return Mono.empty();
}));
}
答案 1 :(得分:0)
如果我正确理解了您的问题,则希望将desktop.html
上的移动用户重定向到mobile.html
,并将mobile.html
上的台式机用户重定向到{{1} }。这将需要以下两个规则:
desktop.html
请注意,这2条规则依赖于user agent,它们永远不会100%可靠(因为它们可以更改)。