我正在尝试设置路由以执行基本的301重定向,并具有同时支持HTTP和HTTPS请求的附加好处。预期结果将是,对http://subdom.domain.org或https://subdom.domain.org的请求将收到301并转发到https://othersub.domain.org/route。实际结果是https://subdom.domain.org 301是预期的,但http://subdom.domain.org 404是预期的。通过配置,您可以看到我已经尝试将HTTPS提升为HTTPS,希望可以在那里捕获规则,但是通过配置中间件的方式,我希望它在两种情况下都可以使用。
这是我当前的配置:
http:
routers:
subdom.domain.org:
entryPoints:
- web
- web-secure
middlewares:
- https-redirect # I've tried with this on and off
- sudbdom-redirect
service: dummy
rule: Host(`subdom.domain.org`)
tls:
certResolver: letsEncryptResolver
middlewares:
https-redirect:
redirectScheme:
scheme: https
subdom-redirect:
redirectRegex:
regex: ".*"
replacement: "https://othersub.domain.org/route"
permanent: true
services:
dummy:
loadBalancer:
servers:
- url: localhost
我最初在匹配特定的正则表达式模式以进行重定向时遇到麻烦,但由于意识到我是按路由应用它的,所以我根本不需要调整模式的范围,通配符匹配在这里似乎工作得很好。任何想法或建议,表示赞赏。谢谢!
答案 0 :(得分:0)
您应该尝试为Web入口点创建2个不同的路由器,其中一个可以执行重定向,而为redirectRegex创建第二个路由器,您可以在其中将应用程序重定向到其他url。