I solved it by disabling site redirection and instead adding this snippet in the custom HTTPD configuration for the domain, to CUSTOM3 so it ends up in the same place:
location /.well-known/ {
}
location / {
# Original site redirection code
rewrite ^/.*$ https://domain.tld permanent;
}...