When you rally, try to reform your units into some sort of formation before you reengage the enemy, they will get a morale bonus for flank protection that will help prevent them all routing again. I usually send all rallied troops to a point (say a hill top) and gradually form a new defensive position. It wont always work though, enemy units may just rout you off the map. But sometimes I have won a 'lost' battle using this method.