.htaccess rule that denies hidden paths. This article walks through that pattern as a post-mortem, from first symptom to a fix that keeps the challenge path open without loosening protection elsewhere.
Impact: renewals fail while the site looks healthy
Investigation: walk the request path layer by layer
/.well-known/acme-challenge/ in the webroot. The CA then requests http://yourdomain/.well-known/acme-challenge/<token> over port 80 and expects the exact token content back. Any layer between the internet and that file can interfere.
The fastest way to find the guilty layer is to reproduce the request from outside your network and then check whether it ever reached the web server. Place a plain text test file in the challenge directory of the webroot your ACME client uses, then run something like this from a machine that is not on the server or office network:
BASH
# From an external machine: request a test file in the challenge path
curl -i 'http://example.com/.well-known/acme-challenge/test-123'
# On the server: did the request reach the web server at all?
# Log path depends on distro and control panel
grep 'acme-challenge' /var/log/nginx/access.log | tail -n 20| Layer | Typical symptom | Where to look |
|---|---|---|
| Host firewall, fail2ban, or geo block | Timeout, nothing in the web server log | Firewall rules and ban lists |
| CDN or cloud WAF in front of the origin | 403 or an HTML challenge page, no hit in the origin log | The WAF event log in the provider dashboard |
| ModSecurity on the origin | 403, with a matching entry and rule ID in the ModSecurity log | ModSecurity audit or error log |
Rate limiting (for example nginx limit_req) | 429 or 503 | Web server error log, for nginx look for 'limiting requests' |
.htaccess or server deny rules | 403 in the access log, no WAF entry | .htaccess in the docroot and parent directories, server config |
The discovery: the validator is not a normal visitor
location ~ /\. { deny all; } or a rewrite rule that rejects any URI containing /.. Let's Encrypt also validates from multiple network vantage points, so a country block or a firewall allowlist can pass one check and fail another. And it does not publish a fixed list of validation IPs, so allowlisting by address is not a dependable strategy.
Redirects are worth a separate note. An HTTP-to-HTTPS redirect is generally fine, because Let's Encrypt follows redirects to the HTTPS URL. But that means the HTTPS side, with its own WAF rules, now has to serve the token too. If the HTTP side passes and the HTTPS side has stricter rules, the failure appears to come from nowhere.
The User-Agent is not a safe key either. It can change, and anyone can send the same string.
Temporary mitigation: get the certificate renewed safely
The lasting fix: a narrow, documented exception
- and _). Everything else on the site keeps full protection.
For ModSecurity on the origin, a chained exclusion that loads before your core rule set does this. The rule ID here is a placeholder, so pick one that does not collide with existing rules:
APACHE
# Load BEFORE the core rule set. Rule ID is a placeholder.
SecRule REQUEST_METHOD "@streq GET" "id:1000101,phase:1,pass,nolog,chain"
SecRule REQUEST_URI "@rx ^/\.well-known/acme-challenge/[A-Za-z0-9_-]+$" "ctl:ruleEngine=Off"/.well-known/acme-challenge/../wp-login.php does not match the regex, so it still gets inspected.
For nginx, give the challenge path its own prefix location with ^~. That modifier stops regex locations, including a dot-file deny rule, from taking over:
NGINX
location ^~ /.well-known/acme-challenge/ {
root /var/www/example; # must match the webroot your ACME client writes to
default_type text/plain;
allow all;
try_files $uri =404;
}limit_req set at server level is inherited by this location. A clean way around it is to build the limit_req_zone key through a map that returns an empty string for the challenge path, because requests with an empty key are not counted.
On Apache with .htaccess, put a condition such as RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/ before any rewrite rule that blocks hidden paths. If the deny comes from authorization directives instead, a small .htaccess inside the challenge directory with Require all granted (Apache 2.4 syntax) usually overrides it. That only works if AllowOverride permits it for that directory.
For a CDN or cloud WAF, the idea is the same, though the exact controls depend on the provider: a skip or exception rule matched on the URI path prefix, limited to GET, applied to bot and challenge features as well as managed rules. Check in the provider's event log that the exception actually matches. For host firewalls and fail2ban, make sure port 80 stays open and that jails watching web logs do not count requests to the challenge path.
Finally, write the exception down next to the rule itself. The next person who hardens the WAF or pastes a new security snippet needs to know why that path is open, or the same failure comes back with the next rule update.
The practical habit is simple: whenever you add or upgrade a security layer, run your ACME client's dry-run renewal right after, from the same server, and watch the result. A 403 or timeout there costs a few minutes to trace. Finding the same failure when the certificate has already expired costs a lot more, and with shorter lifetimes, that day arrives sooner.