PDF files uploaded to the private directory cannot be viewed and returns a 404 error. This also happens to the user with the Administrator role. Other file types can be viewed with no issue. This issue happens in a production environment, hosted on Cloudways, where the private directory is set from the following line in the settings.php file.
$settings['file_private_path'] = $app_root . '/../private';
Steps to reproduce
Login to site as administrator user (the one with the Administrator role)
Add a file field to the Article content type
Set its Upload destination to Private files
Set Allowed file extensions to txt, pdf, doc, docx and Maximum upload size to 1 MB
Set the file directory to article-test (When the server root directory is public_html/web, private files should be uploaded to public_html/private/article-test.)
Create an Article node and upload a valid PDF file whose size is less than 1 MB (doc_0.pdf)
Save and publish the node
View the new node
Click on the file link for the uploaded file, which links to
https://<domain>/system/files/article-test/doc_0.pdf
)The site returns a 404 error
The browser bar shows
https://<domain>/user/login?destination=/system/files/article-test/doc_0.pdf
as URLGo to
https://<domain>/admin/content/files
Click on the file link (
https://<domain>/system/files/article-test/doc_0.pdf
)The site still returns a 404 error
The Drupal log shows page not found Location
https://<domain>/user/login?destination=%2Fsystem%2Ffiles%2Farticle-test%2Fdoc_0.pdf
Remove the uploaded file from the node
Upload a text file or a Microsoft Word file
Viewing the file doesn't return any 404 error
viewing the file, a prompts ask for saving or viewing the file
I don't believe this is a permissions issue; otherwise, I wouldn't be able to access these other file types.
The file permissions for the public_html/private directory and its directories are set to 775. The file permissions for the uploaded files are set to 664.
Is there a setting (PHP, Drupal, or server) I should change to allow the PDF files to be viewed?
There is an .htaccess file in public_html/private directory. Thinking it may be related to the issue, I temporarily renamed it to .htaccess.saved. I then tried to access the uploaded PDF file, still obtaining a 404 error.
One more fact: If the same exact PDF file is uploaded to the site's public directory, the file can be viewed without errors.
.htaccess
is anything to do with this. Is the configured directory for private files on a different filesystem than the public directory?