Rape has nothing to do with having sex. A woman who has been raped has not "had sex" with someone. Having sex with someone - it's an active thing, you are having sex, you are participating, joining in. Being raped is completely different.
The law certainly does not define rape as having sex. It defines it as non-consensual penetration.
When normal people communicate when they mean consensual sex, they say having sex, and when they mean rape, they say rape. I would be surprised that a woman who is familiar with everyday english would interpret the question "when did you last have sex" to be asking about experiences like rape. Most women would think of quite a different question - have you been raped.