Domain-wide basic auth with CakePHP 3

Dear All

I want additional domain wide Basic Authentication with certain freely accessible URIs (APIs from CakePHP).

I have difficulties in tuning up the .htaccess rewrite rule from CakePHP webroot. If I comment out the .htaccess rewrite, the API URI is accessible but returns file not found (as CakePHP does not “serve the URI”). If I leave the rewrite rule, the URI is not accessible without entering the authentication details.

I have asked the question in stackoverflow and I am unsure if I should copy-paste the entire info to this thread or just the link to the question?