Skip to content

Instantly share code, notes, and snippets.

@michaelfox
Created November 8, 2012 21:46
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 michaelfox/4041894 to your computer and use it in GitHub Desktop.
Save michaelfox/4041894 to your computer and use it in GitHub Desktop.
Force WWW
<IfModule mod_rewrite.c>
# Force www
RewriteEngine on
RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http(?%1s)://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
RewriteEngine on
RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment