During the Age of Sail, how did a ship move in the direction it was headed rather than the direction in which the wind was blowing?

by Irregularitied

The rudder must direct the ship, but if a ship hit a headwind, could it travel against it?

roosterrugburn

You wouldn't actually sail against the wind but at an angle to it, this is known as close hauling. Changing course back and forth, known as tacking, will give you a zig zag pattern in the basic direction you wanted to go.

http://skippercourse.com/how-to-sail-basics-of-sailing

There are also different types of sails too. Some are better against the wind than others.