Skip to content

Instantly share code, notes, and snippets.

@zayarwinttun
Created December 1, 2015 16:25
Show Gist options
  • Save zayarwinttun/6f14232f885828755f51 to your computer and use it in GitHub Desktop.
Save zayarwinttun/6f14232f885828755f51 to your computer and use it in GitHub Desktop.
url canonicalization redirect
RewriteEngine On
# www.example.com to example.com
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^/?$ "http\:\/\/example\.com\/" [R=301,L]
# example.com to www.example.com
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment