Yes, this is probably possible. Although you’ll likely have to custom code this in PHP to make this work.
If you’re linking from an external website, the post shared by @jaikrishna.t is relevant. If you’re linking from the same website, it doesn’t affect you.
Although I do want to state that the Referrer header is easy to manipulate by visitors, so you should not rely on it for any kind of security.