Skip to content

Instantly share code, notes, and snippets.

@jeremyyeo
Last active August 29, 2015 14:07
Show Gist options
  • Save jeremyyeo/9a5aee8458d2d073d516 to your computer and use it in GitHub Desktop.
Save jeremyyeo/9a5aee8458d2d073d516 to your computer and use it in GitHub Desktop.
Non-www to www
# Only use either one: non-www to www or www to non-www.
# Redirecting non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Redirecting www to non-www
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteEngine on
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment