Skip to content

Instantly share code, notes, and snippets.

Last active April 7, 2022 14:58
What would you like to do?
.htaccess - fix http to https redirect for DDEV
# Debug trick, uncomment to check values:
# ErrorDocument 404 "Request: %{THE_REQUEST} Referrer: %{HTTP_REFERER}, Host: %{HTTP_HOST}, HTTPS: %{HTTPS}, HTTP:X-Forwarded-Proto: %{HTTP:X-Forwarded-Proto}"
# RewriteRule ^ - [L,R=404]
# The general rule for redirecting HTTP to HTTPS:
# --> Results in "Error too many redirects" in DDEV, because %{HTTPS} is always == off
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Fixed version, check also that HTTP:X-Forward-Proto is off (= http), redirect
# found this via .ddev/apache/apache-site.conf ->
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment