this is based on leaving group tendency.
-Cl is a good leaving group while -OH is weak one.
A strong leaving group can substitute a weak leaving group while vice versa is not possible
to idintify a leaving group, simply make conjugate acid of that gp. A strong acid has weak conjugat base and so a strong leaving gp.