Last active
May 17, 2019 22:05
-
-
Save bert-w/3ee1089f33dd5f7022e8fff52df307b7 to your computer and use it in GitHub Desktop.
Generic htaccess rewrite to HTTPS
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
# Rewrite non-https to https + www | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteCond %{HTTPS} off [OR] | |
RewriteCond %{HTTP_HOST} !^www\. [NC] | |
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] | |
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301] | |
</IfModule> | |
# Rewrite non-https to https without www | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteCond %{HTTPS} off [OR] | |
RewriteCond %{HTTP_HOST} ^www\. [NC] | |
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] | |
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301] | |
</IfModule> | |
# Rewrite non-https subdomain to https subdomain | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteCond %{HTTPS} off [NC] | |
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC] | |
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301] | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment