SANTA CLARA, Calif. (AP)A matchup with the NFC West rival Los Angeles Rams was once again just what the San Francisco 49ers needed to get their season back on track.

A big dose of Christian McCaffrey helped too.

Now the question for the 49ers headed into their bye week off a feel-good 31-14 win over the Rams on Sunday is whether that performance provided the blueprint they need for the second half of the season.

”Probably had our best game as a team yesterday,” coach Kyle Shanahan said Monday. ”I think that was real good timing for it. I think we need this bye week. We need to rest up a little bit and hopefully get some guys back. Right when we get it going a little bit, it is always tough to take some time off, but I do think we need it just for our health and stuff.”

Back-to-back losses to Atlanta and Kansas City left the Niners (4-4) reeling a bit last week. But playing the Rams always seems to be the recipe to get San Francisco going again.

The Niners have won eight straight regular-season matchups in the series and used a win last year against the Rams to turn their season around and make it to the NFC title game where they lost to Los Angeles in the most consequential meeting between the teams.

With McCaffrey sparking the offense with a rare touchdown Triple Crown of one throwing TD, one rushing TD and one TD catch, the Niners had their best game offensively of the season and the defense shut Los Angeles down in the second half.

”It was big,” quarterback Jimmy Garoppolo said. ”We talked about it. Our core group of leaders in there, we try to emphasize to the guys that’s how we’ve made our runs in the past here. It’s how we’ve smothered teams.”

WHAT’S WORKING

Second-half defense. The vaunted Niners defense had struggled in the back-to-back losses to the Falcons and Chiefs and allowed TDs on two of the first three drives against the Rams. Then after halftime, the Niners held the Rams to four first downs, 2.32 yards per play and didn’t allow Los Angeles to cross midfield.

WHAT NEEDS HELP

Red zone penalties. There wasn’t much that went wrong on Sunday, but San Francisco did commit two penalties in the end zone to prolong a drive that ended in the Rams first touchdown.

Ambry Thomas was called for holding on a second-and-goal incomplete pass from the 4 to give the Rams a new set of downs. Then on third-and-goal from the 2, Charvarius Ward was called for pass interference.

STOCK UP

Garoppolo had perhaps his best performance of the season. He completed 21 of 25 passes for 235 yards and two TDs for a 132.5 passer rating. It was his fourth-highest passer rating in a game when he threw at least 20 passes and the fifth-highest completion percentage in franchise history with at least 20 passes.

Garoppolo’s four-game streak with at least two TD passes is his longest ever and tied for the longest for any 49ers QB since Jeff Garcia did it in eight straight games in 2001.

STOCK DOWN

RT Mike McGlinchey struggled in pass protection again, getting beaten for two of the three sacks allowed by the Niners in the game.

This marked the second straight game McGlinchey was beaten for two sacks.

INJURIES

The Niners came out of the game without any injuries for a change. They could get several players back after the bye week, including WR Deebo Samuel, WR Jauan Jennings, FB Kyle Juszczyk, RB Elijah Mitchell, CB Jason Verrett, LB Dre Greenlaw and LB Azeez Al-Shaair.

KEY NUMBER

4. McCaffrey became the fourth player since the merger to throw, catch and run for a TD in the same game, joining LaDainian Tomlinson (2005 vs. the Raiders), David Patten (2001 vs. the Colts) and Walter Payton (1979 vs. the Vikings).

McCaffrey also became the only player in the Super Bowl era to do that and also have at least 30 yards rushing, passing and receiving in a game.

NEXT STEPS

The 49ers have a week off before hosting the Chargers on Nov. 13.

AP NFL coverage: https://apnews.com/hub/nfl and https://twitter.com/AP-NFL