Skip to content

Instantly share code, notes, and snippets.

@anova
Created August 9, 2023 13:23
Show Gist options
  • Save anova/1e75558ff6c36f950ba3d427df0c5a45 to your computer and use it in GitHub Desktop.
Save anova/1e75558ff6c36f950ba3d427df0c5a45 to your computer and use it in GitHub Desktop.
Enforce SSL and www with one redirect. Change example.com with your domain.
# https://stackoverflow.com/a/36986520
RewriteEngine On
RewriteCond %{HTTP_HOST} example\.com$
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://www.example.com%{REQUEST_URI} [L,R=301]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment