Diet makes a big difference as well. Unfortunately, there is no set answer as to what is the best diet. Everyone has to experiment with their diet to see what contributes to their pattern of headaches. Smoking is a definite no-no. Cigarette smoking is definitely associated with cluster headaches.
Relaxation exercises seem to work for most people.
And again, you can't start a relaxation exercise after you get your headache. The pain would make it too difficult to concentrate on relaxing. Regular practice of meditation or relaxation will pay big dividends in preventing tension headaches. Stretching exercises can also help, especially with tension headaches. Rotate your neck slowly and carefully, being careful not to bend your neck backwards.