将HTTP重定向到底层的HTTPS
如何在Undertow中配置HTTP->HTTPS重定向?我已经浏览了Undertow的代码库,有一些类似乎是相关的(例如RedirectHandler)。此外,Undertow documentation()似乎正是针对这个问题。但我不知道从哪里开始 基本上,我要寻找的是Apache的mod_rewrite配置的对应项:将HTTP重定向到底层的HTTPS,https,rewrite,undertow,Https,Rewrite,Undertow,如何在Undertow中配置HTTP->HTTPS重定向?我已经浏览了Undertow的代码库,有一些类似乎是相关的(例如RedirectHandler)。此外,Undertow documentation()似乎正是针对这个问题。但我不知道从哪里开始 基本上,我要寻找的是Apache的mod_rewrite配置的对应项: RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUES
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
谢谢 指向正确的方向。通过编程,必须将SecurityConstraint
添加到Builder
并设置securityportmanager
:
DeploymentInfo servletBuilder = Servlets.deployment();
servletBuilder.addSecurityConstraint(new SecurityConstraint()
.addWebResourceCollection(new WebResourceCollection()
.addUrlPattern("/*"))
.setTransportGuaranteeType(TransportGuaranteeType.CONFIDENTIAL)
.setEmptyRoleSemantic(EmptyRoleSemantic.PERMIT))
.setConfidentialPortManager(new ConfidentialPortManager() {
@Override
public int getConfidentialPort(HttpServerExchange exchange) {
return 443;
}
}
);
使用此方法是否可以使用301永久重定向而不是默认的302重定向?@Thermometer-不确定,从未尝试使用
DeploymentInfo
进行重定向。如果任何人想要完整实现,请参考以下内容