Skip to content

Instantly share code, notes, and snippets.

@underwhelmed
Created April 28, 2015 20:34
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 underwhelmed/f97325139c8a11024085 to your computer and use it in GitHub Desktop.
Save underwhelmed/f97325139c8a11024085 to your computer and use it in GitHub Desktop.
Redirect all http and https traffic from naked domain to www.
# Redirect HTTP without www to HTTP with www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Redirect HTTPS without www to HTTPS with www
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://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