Skip to content

Instantly share code, notes, and snippets.

@lfbittencourt
Last active January 11, 2017 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lfbittencourt/763ef618e20aca5d0235e3b1d23a1238 to your computer and use it in GitHub Desktop.
Save lfbittencourt/763ef618e20aca5d0235e3b1d23a1238 to your computer and use it in GitHub Desktop.
.htaccess to force www or non-www version
# IMPORTANT: if there are another rules, put these ones right after "RewriteEngine on"
# Force non-www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]
# Force www
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment