Last active
May 19, 2022 13:48
-
-
Save vadirajks/ffd6e742fbf66b010820eb379d4978e4 to your computer and use it in GitHub Desktop.
http to https redirect
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
server { | |
# all traffic, secure or otherwise, comes in on 80 from the ELB | |
listen 80; | |
# ELB stores the protocol used between the client and the load balancer in the X-Forwarded-Proto request header. Check for 'https' and redirect if not | |
if ($http_x_forwarded_proto != 'https') { | |
return 301 https://$host$request_uri; | |
} | |
server_name your-secure-site.com www.your-secure-site.com; | |
.... (the rest of your config) | |
} | |
server { | |
server_name example.com www.example.com; | |
listen 80; | |
listen 443 ssl; # Listen for SSL at port 443 as well | |
# ... other config - certificates and such | |
# If a user tries to come through http, redirect them through https | |
if ($scheme != "https") { | |
return 301 https://$host$request_uri; | |
} | |
} | |
<VirtualHost *:80> | |
... | |
RewriteEngine On | |
RewriteCond %{HTTP:X-Forwarded-Proto} !https | |
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} | |
... | |
## option 1 | |
RewriteEngine On | |
RewriteCond %{HTTPS} =on | |
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [QSA,L] | |
## option 2 | |
RewriteEngine On | |
RewriteCond %{SERVER_PORT} !^443$ | |
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L] | |
## option 3 | |
RewriteEngine On | |
RewriteCond %{HTTPS} off | |
RewriteCond %{HTTP:X-Forwarded-Proto} !https | |
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | |
################################################################ | |
## option 4 | |
## https://toster.ru/q/174797 | |
RewriteCond %{ENV:HTTPS} !on | |
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | |
################################################################ | |
## option 5 | |
RewriteCond %{HTTP:X-Forwarded-Proto} !=https | |
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=302,L] | |
################################################################ | |
## option 6 | |
# BEGIN rlrssslReallySimpleSSL rsssl_version[2.3.14] | |
<IfModule mod_rewrite.c> | |
RewriteEngine on | |
RewriteCond %{HTTP:X-Forwarded-Proto} !https | |
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] | |
</IfModule> | |
# END rlrssslReallySimpleSSL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment