With Apache 2.4 or later you could use an IF statement:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
DocumentRoot ~/some-local-unique-path/
<If "%{REQUEST_URI} !~ m#/\.well-known/acme-challenge/#">
Redirect permanent / https://example.com/
</If>
</VirtualHost>
Notes:
- Set your ServerName and ServerAlias appropriately
- Set DocumentRoot to an existing folder just for the ACME challenge file
- Set the domain name in the Redirect statement to your preferred name (from ServerName or ServerAlias)
-
RewriteEngine on
is not required when using justRedirect
as in this example