Nextcloud pretty URLs not working (rewrite)

Hey,
I managed to get achieve pretty URLs (removing /index.php/… from the URI) with this Caddyfile:

    rewrite {                                                            
            ext .js .svg .gif .png .html .ttf .woff .ico .jpg .jpeg .css 
            r ^/(.+)$                                                    
            to /{1} /index.php?{1}                                       
            #r ^/index.php/(.+)$                                         
            #to /{1} /index.php?{1}                                      
    }                                                                    
                                                                         
    rewrite {                                                            
            if_op and                                                    
            if {path} not_has /remote.php                                
            if {path} not_has /ocs                                       
            r /(.*)                                                      
            to /index.php?{query}                                        
            #r ^/.*$                                                     
            #to /index.php?{query}                                       
            #r ^/index.php/.*$                                           
            #to /index.php?{query}                                       
    }

So the page loads fine like this: https://nextcloud.example.com/apps/files but all links inside Nextcloud still include the /index.php/apps format. My nextcloud config php also includes this line:

'overwrite.cli.url' => 'https://nextcloud.example.com',
'htaccess.RewriteBase' => '/',                                  

Maybe I’m missing something?

Best regards,
Jonas