Oil and Gas drilling

I watched a video not long ago and I never knew this law existed and this was going on to this extent.
The video was filmed in the USA in various states, it said there is a law that a person can own the land but not what is underneath it. This gives a drilling company the rights to drill on the land and look for oil or gas etc.
In a lot of cases some of these drilling rigs were close to the houses but the owners of the land couldn’t do anything about it.
There was one farm where the drilling company put up a fence and it restricted the farmer to go on a field, they gave him a key to the gate but only on the condition he locked it straight after he entered, if he didn’t agree he got no key.
Then it shown a map of the US and red dots where all these drilling rigs were the map was almost red with these red dots, they were everywhere.
Seems it was some law passed many years ago and it was never changed, so you could own acres of land but anyone can come and drill on it because you don’t own what is underneath.
So now every time I see stock for oil and gas I think of this.