Skip to content

Instantly share code, notes, and snippets.

@guigmaster
Created April 30, 2015 13:15
Show Gist options
  • Save guigmaster/53561f1dd94a2ab4f82b to your computer and use it in GitHub Desktop.
Save guigmaster/53561f1dd94a2ab4f82b to your computer and use it in GitHub Desktop.
Htaccess Tips
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment