Skip to content

Instantly share code, notes, and snippets.

@billmei
Last active December 14, 2015 22:19
Show Gist options
  • Save billmei/5157844 to your computer and use it in GitHub Desktop.
Save billmei/5157844 to your computer and use it in GitHub Desktop.
.htaccess configuration file for Apache to convert a www website to a non-www website and vice-versa. Example: "http://www.example.com" to "http://example.com"
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment