.htaccess Security Header Rules

The RewriteEngine On line (as you have indicated) isn’t necessary, and pertains to a different module, mod_rewrite. You should remove it from the mod_headers block.

It’s possible that you don’t have the Headers Apache module installed or activated on your host. If it is possible to run the test with some breakage, you could try removing the If block and running the commands in the parent context. If it fails, that’s a good indication that it wasn’t working because Headers wasn’t installed.

If you are on a Debian system (Ubuntu, etc) you can enable the Headers Apache module like so via SSH:

sudo a2enmod headers
sudo service apache2 restart