When you try to enable option RewriteEngine on in .htaccess file you can get error:
/var/www/html/.htaccess: RewriteEngine not allowed here
In this way you need to enable AllowOverride All option.
Go to /etc/apache2/sites-available and edit 000-default.conf (or other conf file of your website):
sudo nano /etc/apache2/sites-available/000-default.conf
Add next block to this file:
<Directory /> AllowOverride All </Directory>
Your config file will be look’s like this:
<VirtualHost *:80> DocumentRoot /var/www/html <Directory /> AllowOverride All </Directory> </VirtualHost>
Save configuration file and restart apache2
sudo systemctl restart apache2