Pain during sex

Why does it hurt when I’m having sex, doggy or if I’m on top, but not when he is on top? ( the pain is my cervix I think... kind of at the bottom of my stomach )