Skip to content

Instantly share code, notes, and snippets.

@kabilashgit
Last active February 5, 2020 11:44
Show Gist options
  • Save kabilashgit/10552adae4e6595e2de98eeaa73edcca to your computer and use it in GitHub Desktop.
Save kabilashgit/10552adae4e6595e2de98eeaa73edcca to your computer and use it in GitHub Desktop.
force https with www to any url
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.
# [NC] is a case-insensitive match
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment