How do I redirect invalid link other than login screen

I installed NextCloud, and working great so far.
After I send public link to the guest, I noticed that guest can see the login screen.
I set up RedirectMatch in Apache site config for
https://myserver
https://myserver/index.php/ etc
and those are redirect to the web page for guest.
but The everybody can still redirect to login page when they access
https://myserver/index.php/[random string]

Then I realized it is not good idea to redirect by apache since I do not have list of links
for nextcloud use after https://myserver/index.php,
Is there any way to redirect or at least just HTTP 404 error rather than loin page to the guest?

I think it is normal.
Why 404 ?
It makes less sense.