How to redirect PDF files in WordPress without breaking old links

Issue Background

A client needed to update a PDF stored in their Media Library. The problem? Changing the filename would break every instance where that file had been shared, including old URLs and direct links on their website or other web pages.

For example:
Old PDF URL: /wp-content/uploads/2024/02/old-document.pdf
New PDF URL: /wp-content/uploads/2025/03/updated-document-v2.pdf

Most WordPress hosts and FTP servers would not process redirects for static files like PDFs. Redirects usually work for pages, posts, or attachment pages, but not media assets directly.

Diagnosis


Standard redirect plugins, server settings, or regular expression rules couldn’t handle this scenario. The fix required a creative solution at the server and WordPress level—one that works with WordPress, handles PDF file URLs, preserves SEO, and allows visitors to access the new PDF automatically.

Solution

✔️ Step 1: Rename the Old File


Using SFTP, FTP, or your hosting file manager, locate the original PDF in the upload folder and rename it, like this: old-document-old.pdf

✔️ Step 2: Create a “Fake” Directory


Inside the same folder, create a directory using the exact same name as the old file (yes—with the .pdf extension): /wp-content/uploads/2024/02/old-document.pdf/

✔️ Step 3: Add a Redirect File


In that new folder, create an index.php file containing this redirect code:

php

CopyEdit

<?php
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: /wp-content/uploads/2025/03/updated-document-v2.pdf”);
exit();
?>

Now, whenever someone clicks the old PDF link, they’ll land on your new, updated version automatically.

Why It Works


➡️ Browsers try to load /old-document.pdf but find a folder instead.
➡️ That folder serves the index.php, which executes a 301 redirect to your new file.
➡️ No broken links. No SEO losses. Just clean user experience.

Final Outcome


✔ No need to manually update old links on your website—or anywhere else.
✔ Users go directly to your new document.
✔ Search engines respect the 301 redirect, maintaining SEO continuity.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *