Skip to content

Instantly share code, notes, and snippets.

@fernandiez
Created March 17, 2017 11:30
Show Gist options
  • Save fernandiez/bdceedb2f609639871859848fff2966c to your computer and use it in GitHub Desktop.
Save fernandiez/bdceedb2f609639871859848fff2966c to your computer and use it in GitHub Desktop.
Redirect domain to https, subdomain to https and non-www to www
# Redirect domain to https, subdomain to https and non-www to www
# http://stackoverflow.com/questions/37614937/htaccess-redirect-domain-to-https-subdomain-to-https-and-non-www-to-www
RewriteEngine on
# redirect no-www to www only main domain, not with subdomain
RewriteCond %{HTTP_HOST} ^(domain\.com)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L]
# redirect http to https all domain
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{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