Is it safe to control a DC motor's RPM with rapidly turning on/off?
First, yes it is possible and it "can" be designed to be safe. This method is called pulse width modulation (PWM). This kind of modulation is used in moderns drives to control AC and DC motors. This modulation works by being way faster than the mechanical response of the motor. You are pulsating the voltage in the miliseconds range while the mechanical time constant of the motor is usually in the order of the second. This result in a low-pass filtering of the signal you send to the motor and the mean voltage applied to the motor will be determine solely by the duty cycle of the pulsation. In your exemple of one milisecond on and one milisecond off, this will results in a 50 % duty cycle at 500 Hz. So if the total voltage you can apply to the motor is 12 V by leaving the switch always on, you will now apply 6 V to it.

However, as you ask for, this method may pose a threat to the electronic switch driving the motor. Any type of motor store a lot of magnetic energy because of the motor winding large inductance. This energy must be dissipated when you turn off the motor winding by your electrical switch. This cause an overvoltage which may destroy your electrical switch if you have no way of supressing that voltage spike. Unsually, this function is accomplished by an anti-parellel diode across the electrical switch. Also, care must be taken to verify that the electrical switch can take the current and voltage stress accros itself or an overheating condition may arise.

To advise this problem, many circuits topologies have been developped. The differents topologies are usually suited for a particular power rating of the motor. I would recommend you to check the half-bridge circuit and the full-bridge circuit to control your motor as they are the most popular. You can easily find litterature on this subject around the Web and in many power electronics books.