Skip to content

Instantly share code, notes, and snippets.

@kevburnsjr
Created December 1, 2009 19:11
Show Gist options
  • Save kevburnsjr/246542 to your computer and use it in GitHub Desktop.
Save kevburnsjr/246542 to your computer and use it in GitHub Desktop.
# Force WWW for http
RewriteCond %{HTTPS} off [NC]
RewriteCond %{HTTP_HOST} !^www\.[a-z-]+\.?[a-z]{2,6}? [NC]
RewriteCond %{HTTP_HOST} ([a-z-]+)(\.[a-z]{2,6})?$ [NC]
RewriteRule ^(.*)$ http://www.%1%2/$1 [R=301,L]
# Force WWW for https
RewriteCond %{HTTPS} on [NC]
RewriteCond %{HTTP_HOST} !^www\.[a-z-]+\.?[a-z]{2,6}? [NC]
RewriteCond %{HTTP_HOST} ([a-z-]+)(\.[a-z]{2,6})?$ [NC]
RewriteRule ^(.*)$ https://www.%1%2/$1 [R=301,L]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment