try getting the referrer url, or you can also pass the previous url in the href link:
to pass the previous url to the href link you can use javascript:
<a href="newurl.html" id="link1">kdjfdkjfkdjf</a> <script> window.onload = function(){ var a = document.getElementById("link1"); a.href = a.href + "?prevurl=" + escape(document.location.href); } </script>
source share