To prevent them, abstinence works, but will have few takers. Switching to a less active position or role also works. But many women are already on the bottom and those who aren't don't want to give it up. Propranolol, a blood pressure reducing drug has also been used. About 40mg can be given on a regular basis or a couple of hours before sex.
Migraine suffers use their ergotamine.
Some people try plain old aspirin. With sex headaches, the woman's anxiety level and feelings about the relationship may be an issue. If all else fails, then just wait. Sex headaches often go away on their own in a matter of weeks or months.