Ectopic pregnancy occurs when a fertilized egg implants outside the uterine cavity, most commonly in the fallopian tubes, but it can also occur in other locations such as the cervix, ovaries, or abdominal cavity. Factors that contribute to ectopic pregnancy include previous pelvic or abdominal surgery, a history of sexually transmitted infections, and certain fertility treatments. Additionally, structural abnormalities in the reproductive tract or conditions that may lead to scarring, such as endometriosis, significantly increase the risk of an ectopic implantation.