It is important to not aggravate your back while performing hamstring stretches. The FAQ on Stretching is a good source of information about a variety of aspects of stretching. My version stretches one leg at a time. Stand with the rear foot approximately two to three feet from the wall. The rear leg should be straight, the front leg is bent and your hands touch the wall.
Feet point straight ahead, heels are on the ground.
Hold for 10 seconds, switch legs, repeat 10 times. Straighten one leg, place it, with the knee locked, on a foot stool. Bend your body and bring your head towards the leg. Hold this position for 10 seconds. Switch sides, repeat 10 times.