Cannot login with .htaccess

I have this config.php (*** substitute sensitive info):

<?php
$CONFIG = array (
  'instanceid' => '***',
  'passwordsalt' => '***',
  'secret' => '***',
  'trusted_domains' =>
  array (
    0 => 'cloud.***.com',
    1 => '***',
  ),
  'datadirectory' => '/var/cloud',
  'dbtype' => 'mysql',
  'version' => '20.0.4.0',
  'dbname' => 'cloud',
  'dbhost' => 'localhost',
  'dbport' => '',
  'dbtableprefix' => 'oc_***',
  'mysql.utf8mb4' => true,
  'dbuser' => 'oc_***',
  'dbpassword' => '***',
  'installed' => true,
  'maintenance' => false,
  'memcache.local' => '\OC\Memcache\APCu',
  'overwrite.cli.url' => 'https://cloud.***.com/',
  'htaccess.RewriteBase' => '/',
);

when I run

sudo -u www-data php /var/www/html/cloud/occ maintenance:update:htaccess

It generates the .htaccess file without errors.

It correctly redirect my index.php to / but I cannot login. It simple redirect back to the login screen without errors.

If I delete the .htaccess file I can login again and when I re-enable it after logged in I can use Nextcloud apps without any problems and the URL rewrites as expected.

So it seems like it is only the login that is broken.

The logs also reveal nothing and browser’s console also show no errors.

Any advice?