Skip to content

Instantly share code, notes, and snippets.

@doitlikejustin
Created August 1, 2013 23:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doitlikejustin/6136424 to your computer and use it in GitHub Desktop.
Save doitlikejustin/6136424 to your computer and use it in GitHub Desktop.
To WWW or not to WWW in .htaccess
#Force the no-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
#Force the www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment