traefik - 使用带有 Traefik 的请求变量将“WWW”重定向到“Non-WWW”?
问题描述
对于我对 Traefik 的新手理解,我提前道歉,但是有没有办法使用基于请求的变量重写为“非 www”域?
我已经在谷歌上搜索了一个多小时,但找不到答案。
这是我如何在 Apache 中执行此操作的示例。您可以看到它正在使用HTTP_HOST
变量:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
我可以看到我可以像这样设置标签:
--label "traefik.frontend.redirect.permanent=true"
--label "traefik.frontend.redirect.regex=^https?://www.example.com/(.*)"
--label "traefik.frontend.redirect.replacement=https://example.com/${1}"
但这需要我example.com
为所有事情做好准备。无论域如何,我都希望这个重定向。谢谢!
解决方案
我在 Traefik Slack 小组中找到了一些帮助,一位用户为我指出了正确的方向。使用他们的文档(https://docs.traefik.io/configuration/entrypoints/#rewriting-url),他能够帮助我编写正则表达式来解决我的需求:
[entryPoints.https.redirect]
permanent=true
regex = "^https://www.(.*)"
replacement = "https://$1"
推荐阅读
- python - Django 中的 GIS 插件抛出 openssl 错误。未定义符号:EVP_md2
- android - 是否有可能做出使intent.getData().getPath() 不以/ 开头的意图?
- python - 如何在此函数的参数中使用变量运行 subprocess.run?
- wordpress - 如何在 Aws 中的 bitnami wordpress bitnami 中获取系统日志
- python - 这里有使用 Python 的 gRPC 中的 Balancer 和 NameResolver 吗?
- angular - 在 IIS 上构建和部署后加载 Angular javascript 文件时出错
- python - 将值与 Pandas DataFrame 中的前一行进行比较
- go - 为什么用户指针指向 golang 中的结构?
- html - 如何使段落随网站上图像的大小移动?(HTML/CSS)
- ansible - 如何在不使用 Ansible 删除目录的情况下删除目录中的文件?