Having been hit from behind 2 1/2 times (the half was when the lady decided she REALLY didn't want to hit me, jumped the curb and landed on the sidewalk. Thank you, Ma'am), I would offer that there are some things we can do to help.
In the car, I stopped quickly for a yellow light, and a small pickup was hoping to make the yellow, and didn't have either the brakes or the reactions to stop in time. Lesson: always check the mirrors as part of the stopping process, especially on the bike.
On the bike, I was hit just as the light turned green. I didn't even know I had been hit, but the pickup's under-bumper plastic got caught up on the rear tire. I stopped to see why the bike wasn't accelerating properly, and found I had a truck attached. Lesson: watch my six. I could have easily flashed the brake lights and/or scooted up a bit to avoid the collision. If stopped in traffic, I stop towards the edge of the lane so I can split the cars if needed. I watch the mirrors and flash the brake lights a couple of times as the next vehicle approaches the braking zone.
You can't prepare for or prevent every possibility, but there are a lot of things you can to to improve your odds.