The rule is very simple, once you're through past the last defender and he fouls you, it's red.
Do you have a link to an official ruling regarding this? I am sure I thought this before, and then was refuted by the TV or someone with higher knowledge than me saying that "last defender" actually counts the goalkeeper.
From the laws of the game:
"A player, substitute or substituted player is sent off if he commits any of the following seven offences... denying an obvious goalscoring opportunity to an opponent moving towards the players goal by an offence punishable by a free kick or a penalty kick."
This raises the question... what is an obvious goalscoring opportunity? The laws are vague, giving a lot of the decision making to referees.
"Referees should consider the following circumstances when deciding whether to send off a player for denying a goal or an obvious goalscoring opportunity:
the distance between the offence and the goal
the likelihood of keeping or gaining control of the ball
the direction of the play
the location and number of defenders
the offence which denies an opponent an obvious goalscoring opportunity may be an offence that incurs a direct free kick or an indirect free kick "
So we can't actually figure it out from the laws.. we have to look at actual in game examples to see how the referees have been instructed to apply the law.
If an obvious goalscoring opportunity only occurred when a goalkeeper was beat, we would hardly ever see non-goalkeepers sent off for denying such an opportunity. There are rare cases that would happen (Luis Suarez at the 2010 world cup), but 99.9% of fouls committed by non-goalies occur in front of the goalie. But field players are regularly sent off for professional fouls with the goalie behind them... I can't site the rulebook here as it's vague on the issue, but I can just tell you that's my experience from watching a decent amount of soccer. 100%.
The link pacovf provided states that "not more than one defender between the foul and the goal," and I agree that the rule is enforced that way. 99.9% percent of the time, that one player is the goalie, so it's almost always a question of, "Is the player committing the foul the last non-goalie defender."