Skip to content

Instantly share code, notes, and snippets.

@ziadoz
Created September 5, 2013 17:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ziadoz/6453657 to your computer and use it in GitHub Desktop.
Save ziadoz/6453657 to your computer and use it in GitHub Desktop.
Apache rewrite non-www to www and vice versa.
RewriteEngine On
RewriteBase /
# Rewrite: non-www to www
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}$1 [R=301,L]
# Rewrite: www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}$1 [R=301,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment