In a content type I have option for pdf file upload, the uploaded files are stored in private folder.
The uploaded file has absolute url of http://example.com/system/files/abc.pdf
At the moment anyone with the absolute url can download the file (no matter the user roles, access and permissions)
I want to redirect visitors to the front page of the website (instead of downloading) if they use the absolute url of pdf in browser to download it.
So far I tried something with JavaScript something like:
$(document).ready(function() {
if(window.location.href.indexOf(".pdf") > -1) {
$(location).attr('href', window.location.protocol + "//" + window.location.host); // Redirect to front page
}
});
Usually this would do the trick if it was rendered webpage where javaScript is loaded, but it doesn't work with pdf files (as javaScript is not loaded while clicking the absolute url of the pdf file).
I have already tried private files download permission module, but that doesn't do what I want, as my downloadable links are accessible to Anonymous users as well.
Any hints, suggestions, how to accomplish this?