The 24-year-old was recently dislodged from the first team by Lionel Letizi despite a string of impressive displays in the absence of the injured Frenchman.
But McGregor has now agreed a new contract with the club and manager Paul Le Guen.
The Ibrox boss said: "We have reached an agreement with Allan until 2009 and I am very happy with that."
Le Guen has also confirmed defender Steven Smith is set to sign a new deal at the club.
The 21-year-old has become a first-team regular this season under the former Lyon boss and is set to commit himself to the club until 2010.
Le Guen added: "We will re-sign Steven Smith until 2010.
"Our priority is to have stability and it is important to keep the best young players, which is why I am happy."
Now the Rangers boss has targeted a new contract for winger Chris Burke, 22, who will be free to speak to other clubs from January 1.
Le Guen said: "We will carry on discussions with Chris and we hope we can get an agreement.
"Yes, I am worried (he could sign for another club in January), but that is the rule and I accept that.
"We want him to re-sign, but it is up to him."
Social Networking Bookmarks