Skip to content

Instantly share code, notes, and snippets.

@ryanscherler
Last active October 8, 2018 20:44
Show Gist options
  • Save ryanscherler/b878180b8e1c9977936d289989e9bae7 to your computer and use it in GitHub Desktop.
Save ryanscherler/b878180b8e1c9977936d289989e9bae7 to your computer and use it in GitHub Desktop.
Apache: Force httpS and non www
<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