To complete one of my favorite hamstring stretches, lay on your back with your left leg straight up against a doorframe, with your heel resting against the frame. Your right leg should be sticking through the open doorway, and can be straight or bent (this is why you want to do this stretch in a doorway instead of against a solid wall). Scoot your hips toward the doorframe and raise your heel to keep your leg straight, until you feel a good stretch in the back of your leg. Stop and hold that position for 60 seconds. The idea is to gradually increase your flexibility until you can rest comfortably with your entire leg flat against the doorframe, at a 90-degree angle to your back. Do the same stretch with your right leg.
I like this stretch because the position makes it easy to completely relax the leg and hip you're stretching, and keep the other leg out of the way. Instead of having to hold your body in place to do a standing or even sitting stretch, the passive nature of this prone position means you can hold the stretch longer without tensing up just to maintain your form.
In terms of improving flexibility long term, remember that there's a difference between the goals of stretching prior to and after exercise. Stretching during your warm-up helps get you ready for the day's workout, but stretching after training is more effective for long-term flexibility gains. When I have athletes who are participating in yoga classes, I like to have them complete a moderate-intensity ride or run that ends within 30 minutes of the start of their class.
One more thing about flexibility in the hamstrings: don't neglect your adductors. These muscles on the inside of your thighs are working almost any time your hamstrings are engaged. Even though they're thought of as the muscles you use to squeeze your thighs together, They work together with the hamstrings in cycling, running, walking, and swimmingactivities that don't feature much, if any, lateral movement. When your adductors are tight, they'll impede the function of your hamstrings, even if your hamstring flexibility is good.