When a water heater is installed in a location where a leak from it could cause damage, today’s standards require that a drain pan (overflow pan) be installed under it. The pan should have a drain line installed on it that runs to a suitable location.

From the International Residential Building code:

P2801.5 Required pan.

Where water heaters or hot water storage tanks are installed in locations where leakage of the tanks or connections will cause damage, the tank or water heater shall be installed in a galvanized steel pan having a material thickness of not less than 0.0236 inch (0.6010 mm) (No. 24 gauge), or other pans approved for such use. Listed pans shall comply with CSA LC3.

If there is no suitable location for the drain line the drain can be plugged, and a water alarm can be installed in the pan. Or a water sensor can be placed in the pan attached to a valve that can turn off the incoming water to the water heater. These are available at plumbing supply houses.