The game was organised after Linfield hosted a fundraising match last May with Gers engulfed by a financial crisis.
Rangers manager Ally McCoist put out a strong side but they struggled to impose themselves on the match in the opening stages.
An Ian Black shot on the half-hour was all the hosts had to show for their endeavours and Matthew Tipton almost gave the Irish Premiership side a surprise lead but he pulled a decent effort wide of the target.
Rangers eventually took the lead three minutes before the interval as Hegarty got on the end of Fraser Aird's deep cross to score in the corner.
But the flow of the game was lost in second half due to a plethora of substitutions.
Linfield skipper Peter Thompson did find the back of the net after 65 minutes but his joy was shortlived as the linesman flagged for offside.
Instead, McCoist's side doubled their lead with the last kick of the game courtesy of a deflected 25-yard shot from young midfielder Murdoch that gave goalkeeper Alan Blayney no chance.