Skip to content

Instantly share code, notes, and snippets.

@krisleech
Created March 15, 2018 16:12
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 krisleech/c714f9e25ff95e6ed828c903aab79b94 to your computer and use it in GitHub Desktop.
Save krisleech/c714f9e25ff95e6ed828c903aab79b94 to your computer and use it in GitHub Desktop.
Redirect all but .well-known to HTTPS
{% if https %}
<VirtualHost *:80>
  ServerName {{ domain }}
  {% for alias in domain_aliases %}
  ServerAlias {{ alias }}
  {% endfor %}

  RewriteEngine On
  {% if letsencrypt %}
  RewriteCond %{REQUEST_URI} !^/.well-known/
  {% endif %}
  RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R=permanent,L]
</VirtualHost>
{% endif %}

This will redirect (with permanent, 301 status) all requests except any to /.well-known/ which is used by LetEncrypt webroot authentication.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment