Last active
October 8, 2018 20:44
-
-
Save ryanscherler/b878180b8e1c9977936d289989e9bae7 to your computer and use it in GitHub Desktop.
Apache: Force httpS and non 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 | |
AddDefaultCharset UTF-8 | |
# ----------------------------------------------------------------------------------------------- | |
# If you only want to allow HTTPS, uncomment the RewriteCond and RewriteRule lines below. | |
# ----------------------------------------------------------------------------------------------- | |
RewriteCond %{HTTPS} off | |
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] | |
# ----------------------------------------------------------------------------------------------- | |
# Redirect users to the non 'www.' version of the site. | |
# ----------------------------------------------------------------------------------------------- | |
RewriteCond %{HTTP_HOST} ^www\. | |
RewriteCond %{HTTPS}s ^on(s)|off | |
RewriteCond http%1://%{HTTP_HOST} ^(https?://)(www\.)?(.+)$ | |
RewriteRule ^ %1%3%{REQUEST_URI} [R=301,L] | |
</IfModule> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment