What could cause me to have pain under my ribs and headaches?

Lots of things. An enlarged organ such as the liver or spleen can cause pain, but so can other problems such as lung infections or malfunctioning ribs. Disorders affecting organs like the liver can also cause chemical changes in the blood such as toxin build-up which can lead to headaches. Rib problems, themselves, due to muscle and soft-tissue connections to the neck and head, can also cause headaches.