Nextcloud + Wordpres URL rewrite (solved)

I’ve got NC 16.03 running under mydomain/cloud and WP running in my domain root.
If I use NC .htaccess rules, then WP breaks. If I use WP .htaccess rules, or combine the two, then the NC DAV service discovery breaks.

Is there any way to combine all the rules and make NC + WP coexist peacefully?

WordPress:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Nextcloud:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteRule ^\.well-known/host-meta /cloud/public.php?service=host-meta [QSA,L]
  RewriteRule ^\.well-known/host-meta\.json /cloud/public.php?service=host-meta-json [QSA,L]
  RewriteRule ^\.well-known/webfinger /cloud/public.php?service=webfinger [QSA,L]
  RewriteRule ^\.well-known/carddav /cloud/remote.php/dav/ [R=301,L]
  RewriteRule ^\.well-known/caldav /cloud/remote.php/dav/ [R=301,L]
</IfModule>

Create virtual hosts and subdomains for both:
www.mydomain
cloud.mydomain
No need for rewrite. You can keep them in complete separated directories, like
/var/www/wp
/var/www/nextcloud

I simply put the NC rules before WP rules, and took out the ifmodule tags, and it works fine.