Prevention is better

 Place mats in front of the house door to trap the dirt.
This will stop outside dirt from getting onto your carpet.

Bear in mind that a dark carpet won’t show dirt and stains as much as a light carpet will.