The only way I have found to keep them alive is with Restore Health spells. I always make them on touch, rather than on target, since it is easy to miss in a melee with the ranged version. You can even miss with it on touch! It is also cheaper.
My usual tactic is to stop at the end of every fight, and go around and heal every npc with me up to full. This often means a lot of waiting around while my magicka rebuilds between casts.
When it comes to the actual fighting, avoid using weapons with a long reach like longswords. They always hit your allies. Instead touch destruction/absorb health spells work best.
But basically, I try to avoid having companions at all. They only get in the way, and make the game harder.