Since the depth of field extends both in front and behind the focal point, the ideal solution is to use manual focus, and to focus on a point somewhere between the foreground and the distance, so that the extreme distance (effectively infinity) is at the far end of the "sharp zone", the closest object in your frame is at the nearest end, and everything in the frame is in focus. This point, at which the depth of field is maximized within the field of view, is known as the hyperfocal distance.
Calculating exactly where this hyperfocal point lies is a bit tricky and involves a little bit of mathematics, for which I sincerely apologise, but I'd only get angry emails from other photographers if I didn't include this.
In this formula, H is the hyperfocal distance (measured in millimetres), f is the focal length of the lens (also in millimetres), N is the f-stop number of the aperture, and c is the diameter of the "circle of confusion" limit, the acceptable degree to which the image will be blurred. In conventional photography the accepted value of c is approximately 0.03mm, since that results in a level of blurring so faint that the human eye can barely perceive it, so for example with a 28mm lens at an aperture of f22, the hyperfocal distance, the point at which depth of field is optimised, is:
Or just over 1.2 metres. As you can see, setting your camera on infinity means that you are missing out on a lot of potential foreground detail. It also shows that you don't necessarily have to use the very narrowest aperture setting. Using the same 28mm lens at a wider aperture setting setting of f11 still gives a hyperfocal distance of approximately 2.4m, and will produce better image quality.
Fortunately those of us who have joined the 21st century and bought a digital camera have a massive advantage over those Luddites still lumbering along with their stone-age film cameras. A film-using landscape photographer has to know that formula and apply it, and then hope that their calculation was correct. For those of us blessed with LCD monitor screens and instant image review, we can experiment with different focus settings to find out what works, and be sure of accurate results in the final image. However I'm a firm believer in understanding the science behind photography, because knowing how your camera works and why your pictures look the way they do will help you to avoid making mistakes, and will result in much better photographs. It's worth spending a while with a calculator plugging different numbers into the formula and finding out what to try the next time you're out with your camera.
Link to Part 2 of this tutorial.