-
-
Save kongondo/79d359134547366eb3ed842e450b543e to your computer and use it in GitHub Desktop.
.htaccess - fix http to https redirect for DDEV
This file contains hidden or 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