重写规则可用于重定向用户。在undertow子系统(standalone.xml或domain.xml)中,你需要创建一个新的重写过滤器,然后在新的fitler-ref中启用该过滤器:
在过滤器部分中创建新的重写过滤器。在下面的示例中,用户将被重定向到
https://myhostname:443/my-app。%U是原始请求URL路径的占位符;你想使用%U使重定向友好,并保留用户的原始请求URL路径。
<filters><rewrite name="http-to-https" redirect="true" target="https://myhostname:8443%U"/></filters>
然后,启用过滤器并在主机部分中配置谓词。谓词是你在其中配置重写过滤器的对象。在下面的示例中,我们的重写筛选器将仅应用于去往端口8080的请求。
<server name="default-server"> <host name="default-host" alias="localhost"> ... <filter-ref name="http-to-https" predicate="equals(%p,8080)"/>
以下是上述相同配置更改的JBoss CLI步骤:
/subsystem=undertow/configuration=filter/rewrite=http-to-https:add(redirect="true",target="https://myhostname:8443%U")/subsystem=undertow/server=default-server/host=default-host/filter-ref=http-to-https:add(predicate="equals(%p,8080)")



