Skip to content

Instantly share code, notes, and snippets.

@gnilchee
Created November 2, 2014 07:45
Show Gist options
  • Save gnilchee/4ebcbf139cd4d5428206 to your computer and use it in GitHub Desktop.
Save gnilchee/4ebcbf139cd4d5428206 to your computer and use it in GitHub Desktop.
redirect ANY naked domains to www.domain.tld
## This is to allow all incoming naked domains to be rewritten as www.domain.tld
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment