Apache redirect everything except ACME challenge requests EXAMPLE

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:

  1. Set your ServerName and ServerAlias appropriately
  2. Set DocumentRoot to an existing folder just for the ACME challenge file
  3. Set the domain name in the Redirect statement to your preferred name (from ServerName or ServerAlias)
  4. RewriteEngine on is not required when using just Redirect as in this example
4 Likes