The substitution reaction is of two types (both of them being nucleophilic substitution):
i). SN1: In this substitution, the halo-ion leaves the molecules forming a stable carbocation intermediate. Later, another nucleophile, who has more affinity to the cation attaches itself to the carbocation to form a new molecule. It's called SN1 because the rate determining step has one order.
ii). SN2: Here, a more electronegative nucleophile attacks the molecule from the opposite side to the halogen atom and it gets attached slowly as the halogen is leaving the substance simultaneously. At last, the halogen finally leaves and the original compound is flipped in its orientation.
For intra-molecular re-arrangement of haloalkanes, there are two cases:
i). In SN1 substitutions, the carbocation formed might undergo hyper-conjugation to form an even more stable carbocation which is then later attached to the nucleophile.
ii). For reactions proceeding via the SN2 mechanism, the flipping of structure results in inversion of configuration for chiral substrates. Thus chiral compounds are re-arranged in SN2.