The full-back has been released from his contract at Ashton Gate, which had a year remaining, and will be registered with the Irn-Bru Third Division champions on September 1.
Foster previously spent the 2010/11 campaign on loan at Ibrox while contracted to Aberdeen.
A transfer embargo means the Light Blues must wait until September to register players, who must be free agents.
A statement on the club's website read: "Foster arguably gave his best performances for Rangers on the European stage as he featured both in the Champions League and the Europa League at right wing-back.
"In total, he made 24 appearances which he will now add to as the forthcoming Second Division campaign progresses."
The 27-year-old made 51 appearances for City.
- Sports & Recreation