Fix PDFs Not Opening After Web Host Migration
In this article
After migrating your website to a new web host, PDFs that previously worked may suddenly fail to open, showing errors like "Failed to load PDF document" or downloading as garbled files. This usually happens because of incorrect file permissions, missing MIME types, corrupted file transfers, or outdated cached versions. This guide walks you through the most common fixes, from simple cache clears to server configuration changes, so you can get your PDFs working again quickly.
What You'll Need
- Access to your web host's control panel (cPanel, Plesk, or similar)
- FTP or file manager access to your website's files
- A text editor (like Notepad++ or VS Code) for editing configuration files
- Your website's backup (if you have one) for comparison
Step-by-Step
- Check file permissions on the PDF files. Using your FTP client or file manager, navigate to the folder containing your PDFs. Right-click each PDF (or the whole folder) and check permissions. They should be set to
644(owner read/write, group read, others read). If they are600or700, the web server cannot read them. Change them to644and re-test. - Verify the PDFs were uploaded in binary mode. If you used FTP to transfer files, ensure your FTP client is set to "Binary" mode (not "ASCII" or "Auto"). ASCII mode can corrupt binary files like PDFs. Re-upload the PDFs in Binary mode if you suspect corruption.
- Clear your browser cache and try a different browser. Sometimes the issue is just a cached old version of the PDF or the page linking to it. Hard-refresh (Ctrl+F5 on Windows, Cmd+Shift+R on Mac) or open the PDF URL directly in an incognito/private window.
- Check the PDF URL for case sensitivity. Linux servers are case-sensitive. If your PDF is named
Report.pdf, a link toreport.pdfwill fail. Use the exact filename from your file manager. - Verify the MIME type for PDFs is set correctly on the server. In cPanel, go to "MIME Types" (under the "Advanced" or "Files" section) and ensure
.pdfis mapped toapplication/pdf. If not, add it. For other hosts, you may need to edit the.htaccessfile (Apache) orweb.config(IIS) to add:AddType application/pdf .pdf(for Apache). - Check the .htaccess file for conflicting directives. If you have a
.htaccessfile, look for rules that might block or redirect PDF requests. Common culprits are hotlink protection or rewrite rules. Temporarily rename.htaccessto.htaccess_backupand test a PDF. If it works, you need to adjust your rules. - Ensure the PDF files are not corrupted during migration. If you used a migration plugin or copied files manually, some PDFs might be incomplete. Compare file sizes with your original backup. If they differ, re-upload the correct files.
- Test a simple PDF file. Create a tiny test PDF (e.g., print a one-page document to PDF) and upload it to the same directory. If that opens, the issue is specific to your original files, not the server.
- Check for any security modules (like ModSecurity) blocking PDFs. Some web hosts have security rules that block certain file types. Contact your host's support and ask if ModSecurity or similar is blocking PDF requests.
- If using a CDN, purge the cache. If you use Cloudflare or similar, clear the cached PDFs from the CDN. Otherwise, visitors may get an old or broken cached version.
- Verify the link in your HTML is correct. Open the page source and click the PDF link. Ensure the href points to the correct path (relative or absolute). Sometimes migration changes the site URL, breaking relative links.
Common Mistakes
- Forgetting to set permissions after upload. Many FTP clients default to 644, but if you upload via a script or plugin, permissions can be off.
- Uploading PDFs in ASCII mode. This is a classic error that corrupts binary files silently.
- Assuming the migration tool copied everything perfectly. Always verify file integrity after migration.
- Ignoring the server's error logs. The logs often contain the exact reason (e.g., "File not found" or "Permission denied").
Tips
- Always keep a local backup of your PDFs and compare checksums (e.g., MD5) after upload to ensure integrity.
- Use a dedicated PDF directory (e.g., /pdfs/) to make permission management easier.
- If you're on shared hosting, contact support early—they can quickly check server-side issues.
- For large numbers of PDFs, use an FTP client that supports queueing and binary mode by default (like FileZilla).
Troubleshooting
If the steps above don't resolve the issue:
- Check the server error log. In cPanel, go to "Errors" or "Raw Access Logs". Look for entries around the time you tried to open a PDF. Common errors: "Permission denied", "No such file or directory", or "ModSecurity: Access denied".
- Try accessing the PDF via a direct URL. If it works, the problem is in the linking page (e.g., a broken relative path). If it fails, the problem is server-side.
- Test with a different device/network. If it works on your phone's data but not your office Wi-Fi, a firewall or proxy might be blocking PDFs.
- If you have a staging site, test there. This helps isolate if the issue is specific to the production server.
- If nothing works, re-upload the entire PDF folder from your backup. This eliminates any hidden file corruption.
Frequently Asked Questions
Why did my PDFs work before migration but not after?
Migration often changes server configuration, file permissions, or the way files are transferred. The new server might have stricter security or different MIME settings.
What does "Failed to load PDF document" mean?
This usually means the browser received a response that isn't a valid PDF. It could be an HTML error page (like 403 or 404) or a corrupted file.
Do I need to change file permissions for every PDF?
No, you can change the permissions on the folder and apply recursively in most FTP clients. But 644 is the standard for files.
Can I fix this without contacting my host?
Yes, most issues are fixable via file manager or FTP. However, if it's a server-level block (like ModSecurity), you'll need host support.
What if my PDFs are stored outside the public_html folder?
Then the web server can't access them. Move them to a public directory or set up a symlink.
Is it safe to edit .htaccess?
Yes, but make a backup first. A syntax error can cause a 500 error, but you can restore the backup via FTP.