2

I need help to understand how to do HTTP redirects to HTTPS when using apache-fpm in DDEV.

T3 site 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

that works fine when calling in safari https://sample-project.ddev.site/ but when calling in safari sample-project.ddev.site it does not work I get an T3 oops so I have inserted in .htaccess (equivalent to my hosting server)

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

now safari moans too many redirects and I wonder where these redirects come from and why, no redirects in T3 backend are set, no further changes to .htaccess vs the original T3 .htaccess I was expecting ddev to simply redirect sample-project.ddev.site to https://sample-project.ddev.site/

rfay
  • 9,963
  • 1
  • 47
  • 89
skyfreak42
  • 55
  • 1
  • 8
  • Not TYPO3 related really. These rules will cause a redirect from `http://sample-project.ddev.site` to `http://sample-project.ddev.site/` then to `http://sample-project.ddev.site//` then to `http://sample-project.ddev.site///` then to `http://sample-project.ddev.site////` and so on without ever coming to TYPO3. – User366 Jan 18 '21 at 16:33
  • Why do you use "!off"? Your condition then is: When HTTPS is on, then redirect to HTTPS? This is why it results in too many redirects. – Sven Aug 29 '22 at 10:41

1 Answers1

13

Please use this redirect. Since ddev-router is terminating HTTPS, it sets X-Forwarded-Proto, but the ddev-webserver (where you are putting the rule) is actually getting the traffic via HTTP.

  RewriteCond %{HTTP:X-Forwarded-Proto} !https
  RewriteCond %{HTTPS} off
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
rfay
  • 9,963
  • 1
  • 47
  • 89