Skip to content

Instantly share code, notes, and snippets.

@bransinanderson
Created January 20, 2016 23:29
Show Gist options
  • Save bransinanderson/0df0ef6e6428725a483a to your computer and use it in GitHub Desktop.
Save bransinanderson/0df0ef6e6428725a483a to your computer and use it in GitHub Desktop.
# Option 1:
# Rewrite "www.example.com -> example.com"
<IfModule mod_rewrite.c>
# If not an SSL request WITHOUT WWW
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteCond %{HTTP_HOST} !^(local\..+|staging\..+|.+dev)$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# If not an SSL request WITH WWW
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteCond %{HTTP_HOST} !^(local\..+|staging\..+|.+dev)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
# If SSL request WITH WWW
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment