The pills you normally take, containing proteins and vitamins as well as many drugs, are gastro-resistant capsules: they are soluble only when pH is above 6 (when it reaches 7, they've already gone). This protects your stomach and the content of the capsule.
The few medicines that don't present these 'envelops', generally speaking, are absorbed ONLY in the first part of the intestine: here the pH is low enough for keeping most of them undissociated (hence, easier to pass through a lipophilic barrier). Only extremely lipophilic substances can be accidentally absorbed by your stomach (it's called secondary absorption).
A general rule, although presenting many exceptions, says an acid substance (drug, vitamin, protein, amino acid) is absorbed when its pka>pH. On the contrary, a basic drug when its pKa<pH.
I think that now it's clear enough how the pH affects absorption, isn't it?