For infants, prior to them being called diapers they were wearing clouts. These are the same as modern cloth diapers, it's just that the name diaper actually comes from a popular textile used for clouts, as well as other clothing items. Diaper cloth is a cotton woven in a way to create layering appearing a bit like quilting, making it very absorbent. A square is folded into a triangle and wrapped around the child, pinned into place. Often, over this, is worn a wool garment called a pilch. It's there to help prevent leaks.
Women have dealt with menstruation in different ways, usually relying on rags attached to a belt or the undergarments, extra layering of fabrics, or actually doing nothing. Amenorrhea would have been much more common, caused by malnutrition or heavy physical labor. It's seen today in female athletes, but between pregnancies and body stress menstruation may have been less of an issue for many women. An average Western woman in the 18th or 19th century would have worn a chemise/shift, at least one under-petticoat, an outer petticoat, and a gown. Layer in a wool under-petticoat or an extra apron turned around and, though requiring cleaning, would keep from reaching the outer layers. Menstruation and the Female Body in Early Modern England has some sections available online. The author, Sara Read, has also done a Podcast with us and the topic does come up there.
To add, here's a previous answer about antiquity.