Apache mod rewrite rules for Letsencrypt renewal and HTTPS redirection

Just a note on resolving the case when we need to redirect all the requests to HTTPS but need to use the letsencrypt automatic HTTP verification.

Put in your .htaccess or in apache virtualhost definition these rules to redirect all HTTP request to HTTPS except the letsencrypt certbot requests.

The rule will exclude to HTTPS redirection the requests that contains the .well-known folder used by letsencrypt.

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(\.well-known)/ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]