You can achieve this by removing href attribute in anchor tag and adding onclick function to the anchor tag. In onclick function send some parameter in url to get that value in your html page when user visits the page.
Click here to know how to send parameter in url.
Click here to know how to get post parameter from the url .
Still you have any confusion, you can comment your questions to this answer.
If you are using php you can get post parameter from url in a single line of code by using $_REQUEST["your post parameter name"];
I am adding a simple example for this to achieve with simple html and jquery.
with jquery document.referrer method on document ready(when user opens a page), you can get the previous url of user visited. like bellow example. for this you need to include jquery in your page by following line inserting in your page.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
console.log(document.referrer);
if(document.referrer == "your url") {
your code to allow user if comes from the url you mentioned //user will get download button or you can write direct download option;
} else {
window.location = "some url"; //you can redirect user to specific url
}
});
<script>