are in the same division as the 49ers, starting in 1950 when the 49ers and Browns moved from the old AAFC to the NFL, and excluding the St. Louis years of 1995-2015.
Much of the reason for this involves the NFL's one-time inclination to schedule December games in warmer climates as frequently as possible. For most of the 1950s and 1960s, both LA and SF finished at home against teams from colder climates (most frequently the Packers and the Colts). Both teams finished on the road more frequently in the 1970s, but not against each other (the Rams finished with an opponent from outside their division every year from 1970-1978).
The Rams finished at SF for the first time in 1984, and did so again in 1986, 1987, and 1988. It didn't happen again until 1998, by which times the Rams were in St. Louis. The 49ers closed the 2002 season at St. Louis (the final time a Week 17 game was played on Monday night), and again in 2009 and 2011. The Rams' final game as a St. Louis team was at SF in 2015.
The NFL began mandating intra-division matchups for Week 17 in 2010, which increases the chances of future season-ending Ram-49er games.