If you are using Docker setup for Yii2 Advanced application template to build REST API as I do, you could be interested in the command below:
tee /app/api/web/.htaccess <<EOF RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php EOF
it is generating .htaccess configuration file for Apache web server to redirect all requests from not existing files or directories to index.php file in API web application inside Docker container.
Multiple lines below starting <
Web server Apache Mod_rewrite module should be installed and enabled to make it work.