使用 Apache 在 DDEV 中重定向 HTTP -> HTTPS

Redirect HTTP -> HTTPS in DDEV using Apache

我需要帮助来了解在 DDEV 中使用 apache-fpm 时如何将 HTTP 重定向到 HTTPS。

T3 站点 config.yaml

base: 'https://sample-project.ddev.site/'

ddev config.yaml

name: sample-project
webserver_type: apache-fpm
router_http_port: "80"
router_https_port: "443"
use_dns_when_possible: true

在 Safari 中调用时工作正常 https://sample-project.ddev.site/ 但是在 safari sample-project.ddev.site 中调用时它不起作用我得到一个 T3 oops 所以我插入了 .htaccess(相当于我的托管服务器)

RewriteCond %{HTTPS} !off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}/ [L,R=301]

现在 safari 抱怨太多重定向,我想知道这些重定向来自哪里以及为什么,没有设置 T3 后端中的重定向,没有进一步更改 .htaccess 与原始 T3 .htaccess 我期待 ddev 简单地将 sample-project.ddev.site 重定向到 https://sample-project.ddev.site/

请使用此重定向。由于 ddev-router 正在终止 HTTPS,因此它设置了 X-Forwarded-Proto,但 ddev-web 服务器(您放置规则的位置)实际上是通过 HTTP 获取流量。

  RewriteCond %{HTTP:X-Forwarded-Proto} !https
  RewriteCond %{HTTPS} off
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]