Last active
October 3, 2024 09:15
-
-
Save mandrasch/228f8fb8f3738fe4c7b8e2295af578aa to your computer and use it in GitHub Desktop.
.htaccess - fix http to https redirect for DDEV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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] | |
</IfModule> | |
# Fixed version, check also that HTTP:X-Forward-Proto is off (= http), redirect | |
# found this via .ddev/apache/apache-site.conf -> https://gist.github.com/nurtext/b6ac07ac7d8c372bc8eb | |
<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] | |
</IFModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment