I believe the index.html in your theme folder will always overwrite the index.html generated from the mendix deployment process.
You can use JS within script tags to for instance access the remoteUrl to determine the environment.
https://apidocs.rnd.mendix.com/8/client/mx.html