Enabling compression in .htaccess file is causing 500 internal error

When I go to the dashboard>settings>permalinks and click save changes, this code disappears

It sounds like WordPress is overwriting your htaccess file when you save. Thus, your changes are gone.

Perhaps set this up outside of the htaccess in the apache config? Or ask your host to do this for you. Then WP can’t overwrite it 🙂