Generate .htaccess config file using tee shell command

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

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 < and closing EOF are the configuration file content. Such multiple lines syntax is called heredoc. You could choose any other identifier (one word in upper case letters) instead of EOF if you want.

Web server Apache Mod_rewrite module should be installed and enabled to make it work.