Skip to content

Instantly share code, notes, and snippets.

@crystalw
Created September 2, 2012 04:20
Show Gist options
  • Select an option

  • Save crystalw/3594819 to your computer and use it in GitHub Desktop.

Select an option

Save crystalw/3594819 to your computer and use it in GitHub Desktop.
.htaccess preferred domain redirect
# 301 direct to preferred domain
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^yourdomain.com$ [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]
# End 301 direct
# 301 direct to preferred domain
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
# End 301 direct
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment