There was a question similar to this, and /u/RobWithOneB gave an excellent answer. So called 'Russian Saps,' shallow tunnels, could be dug under no man's land and then blown open when an offensive began, to allow troops to attack positions without an exposed advance across no man's land.
There were problems with this, and even greater problems with the idea of simply tunneling underground. For one thing, 'Saps' or tunnels could suffer from instability and cave in, trapping and likely killing troops inside. 'Russian Saps' in particular would betray the direction of an attack, as well as it's imminence, by their construction (a reservation held by many officers prior to the Somme). Tunnels or 'Saps' would need to be dug weeks if not months in advance, and this would impose hefty delays on operations. The enemy could dig a Camouflet or counter-mine, and blow your tunnels as they were being dug, and the earth might not necessarily be ideal for tunneling in the first place. Although tunneling was carried out near Ypres, notably the Messines Mines, these required extensive pumps to remove water and allow the miners to do their work. Mining operations were expensive and time consuming, and time and treasure were of limited availability to Franco-British and German military leadership on the Western Front. More importantly, improvements in tactics and increases in artillery and other advanced military equipment meant that by 1917 at least, a set-piece attack had a very reasonable chance of success on the Western Front.