Skip to content

Instantly share code, notes, and snippets.

@jacks0n
Last active August 29, 2015 14:11
Show Gist options
  • Save jacks0n/c39d60b47a71d8f36d0a to your computer and use it in GitHub Desktop.
Save jacks0n/c39d60b47a71d8f36d0a to your computer and use it in GitHub Desktop.
Force the www or non-www canonical domain (example.com => www.example.com or www.example.com => example.com). Includes re-directing files/assets.
# Force the canonical www-subdomain
# example.com => www.example.com
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Force the canonical root domain
# www.example.com => example.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment