Cell migration plays a major role in many fundamental biological processes, such as morphogenesis, tumor metastasis, and wound healing. As they anchor and pull on their surroundings, adhering cells actively probe the stiffness of their environment. Current understanding is that traction forces exerted by cells arise mainly at mechanotransduction sites, called focal adhesions, whose size seems to be correlated to the force exerted by cells on their underlying substrate, at least during their initial stages. In fact, our data show by direct measurements that the buildup of traction forces is faster for larger substrate stiffness, and that the stress measured at adhesion sites depends on substrate rigidity. Our results, backed by a phenomenological model based on active gel theory, suggest that rigidity-sensing is mediated by a large-scale mechanism originating in the cytoskeleton instead of a local one. We show that large-scale mechanosensing leads to an adaptative response of cell migration to stiffness gradients. In response to a step boundary in rigidity, we observe not only that cells migrate preferentially toward stiffer substrates, but also that this response is optimal in a narrow range of rigidities. Taken together, these findings lead to unique insights into the regulation of cell response to external mechanical cues and provide evidence for a cytoskeleton-based rigidity-sensing mechanism.