I guess you can't but I'm not quite sure. Say it attacks an ally at low health and they can't get out of range in time, is there any way to make the turret hit you instead (if no minions are around)?
is there any way to make the turret hit you instead (if no minions are around)
The only way to cause a turret to attack you is to damage an opponent's champion within range of the turret. This will cause the turret to focus you instead.
You can cause the turret to quit attacking by using the item Ohmwrecker.
It may also be possible to shield or move an ally away from the turret, like with Thresh's lantern.
Once a target has been acquired, a turret doesn't change targets until its current one is dead. This is precisely what allows for turret tanking to be viable.
There is an item called Ohmwrecker which stops a turret from attacking for 3 seconds.
The wikia page is pretty clear about this :
Turrets will continue to attack their current target until the target dies, leaves attack range, or becomes untargetable due to abilities or items.
If an enemy champion within range deals damage to an allied champion (including via damage over time or a pet), the turret will change targets to that enemy champion unless the turret is already targeting another enemy champion.
This can be exploited to force a turret to attack you by dealing the first bit of damage. But once it's done, you cannot undo it.
You can attack an enemy champion, but this will only work if your ally did not attack an enemy champion before you. Note that the enemy champion must also be within the turret's range.
As several others said, you can use the Ohmwrecker, which will make the tower stop shooting.
There are also abilities that the champion targeted by the turret can use. Abilities that make you disappear from the game for just a fraction of a second, such as Shaco's Hallucinate and Master Yi's Alpha Strike, will force the turret to change focus to another target.
Destroying the tower also works. If you destroy a tower after it shoots but before the bolt hits the target, the target will not take any damage.