Created
July 29, 2020 22:29
-
-
Save filkris/792da0678f516a388b50acdff2a9708a to your computer and use it in GitHub Desktop.
Apache force https and non-www or www
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
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
# Do not use both | |
# (1) Force HTTPS and NON-WWW | |
RewriteCond %{HTTPS} off [OR] | |
RewriteCond %{HTTP_HOST} ^www\. [NC] | |
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] | |
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301] | |
# (2) Force HTTPS and WWW | |
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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment