Some good info here. Stance & grip could be an issue.
You say you're very good with a rifle, though, but lousy with a handgun. I'm gonna go out on a limb here and guess you're very good with a scoped rifle. Part of your problem may be a sight picture issue, i.e. not getting a good one and focusing on the front sight. If you're not sure, look up what a good sight picture ought to look like. Aim, get this good sight picture, then focus everything you've got on the front sight, and keep your focus on it while you're shooting, i.e. don't peek at the target or lower the gun or change your grip in between shots to see how you're doing. Theoretically, being an accurate shot is easy - just get a perfect sight picture, focus on the front sight, then pull the trigger without disturbing your sight picture. In practice, though, it's very hard to do. Dry fire practice is good for this.
IMO, another temptation with semi-autos (in the context of learning to shoot) is to shoot too fast. Don't rush your shots. Your .22LR revolver would be good to practice with - in addition to being inexpensive practice, it forces you to slow down. I'd start with it by cocking the hammer and shooting in SA mode. A good DA trigger pull takes a lot of practice and a skill well worth developing, but shooting your revolver in SA mode for now eliminates one of the variables you don't need to be messing with now. For that matter, shooting your revolver in SA mode off a rest reduces the shooting to its essence - sight & trigger control. Once you get decent groups this way, stand and shoot SA offhand, then go to offhand in DA with the revolver or offhand with your 9mm.
In addition to Googling, and the links provided, try the search function on forums like this - there's some good info right here.
Good luck!