Skip to content

Instantly share code, notes, and snippets.

@brandonhimpfen
Created December 1, 2013 01:00
Show Gist options
  • Save brandonhimpfen/7727338 to your computer and use it in GitHub Desktop.
Save brandonhimpfen/7727338 to your computer and use it in GitHub Desktop.
Force the WWW at the Beginning of the URL
# Rewrite example.com → www.example.com
# Use with caution, as this may cause subdomains to forward as well.
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteCond %{HTTP_HOST} !=localhost [NC]
RewriteCond %{HTTP_HOST} !=127.0.0.1
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment