Blog: SEO
Light up Arrows pointing right

How To 301 Redirect a PDF in WordPress for SEO

Avatar for John Locke

John Locke is an SEO consultant from Sacramento, CA. He helps manufacturing businesses rank higher through his SEO agency, Lockedown Design.

In previous articles, we have talked about 301 redirects, and why they are important for SEO.

Essentially, any time you have an external link built to a page or resource, you want that link to continue resolving to a page.

What you don’t want is your old back links to resolve to a 404 (Page Not Found). This is both a bad user experience, and a waste of any link equity that you have built up for your site.

Unfortunately, what happens a lot of the time, especially in organizations that have been around for many years, is a phenomenon called link rot.

This is when links get broken over time, because URLs have changed, and no one has built redirects to new web addresses.

One Thing You May Not Know About Redirecting PDFs to New URLs

Here’s one things that I noticed when trying to redirect a PDF URL to a new URL. On many servers, using .htaccess redirects, or even a plugin like Redirection will have no effect. This is because most servers are configured to resolve directly to the PDF URL.

Now, if you are on a Linux server, doing a 301 redirect for a PDF can be done by editing the .htaccess file.

301 Redirecting a PDF on a Linux Server

The .htaccess file is a special file at the root of your hosting instance. You can usually access and edit this through SFTP, SSH, or a File Manager (if your hosting provider has this in your admin panel).

This is by far the most preferable route to go. Simply add the line below to your .htaccess file.


Redirect 301 /olddoc.pdf http://yoursite.com/newpage.html

The first part of the redirect says this is a permanent redirect, the next part is the legacy PDF URL. The last part is the new URL you want to the PDF to resolve to.

But, if you have an Apache server, the process gets a little more complicated. (Don’t worry though, you’ve still got this!)

Redirecting a PDF URL via PHP

Many hosts use Apache for their server. Many of the managed WordPress hosts actually use an Apache server with an NGINX layer on top for the admin. The point is, redirecting a PDF to a new URL is not as simple as setting up other 301 redirects.

Luckily, I found there is a clever workaround to this dilemma. (I didn’t think of it, but I’m happy to share how it works).

In this method, we will use PHP to redirect the old PDF address to your new web address.

Step 1: Rename your old PDF file. The reason for this is, we are going to set up a pathway for the server to process, so there cannot be a name conflict. If the PDF you are trying to redirect is named mydocument.pdf, you can rename it something like mydocument-old.pdf.

Step 2: Go to the directory path where your old PDF is, and create a new directory with that PDF’s name. In other words, if your legacy PDF was named mydocument.pdf, then that is exactly what the name of your new directory is named. So far, so good.

Step 3: Crate a file in that new directory called index.php.

Step 4: Add the following code to the index.php file and save it back to the server. Where it says Location, that’s where you add whatever URL you want to 301 redirect the old PDF towards.


<?
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.yoursite.com/the-new-url-you-are-pointing-at" );
?>


What we are essentially doing here is forcing the server into reading the new directory path as the old PDF web address. The server then reads the index.php file and does a 301 redirect to the new URL.

If the old file path was http://www.yoursite.com/pdf/mydocument.pdf, the new path is http://www.yoursite.com/pdf/mydocument.pdf/index.php, which does the 301 redirect.

This is really useful if you have a bunch of old back links built up, which you cannot change, but need to redirect to a new resource.

Avatar for John Locke

John Locke is an SEO consultant from Sacramento, CA. He helps manufacturing businesses rank higher through his SEO agency, Lockedown Design.

9 comments on “How To 301 Redirect a PDF in WordPress for SEO

  1. Yep, redirecting a pdf to another page is def a valid SEO tactic.
    I’ve had PDFs rank quite well for mid volume search terms, and then just redirected users to a new landing page instead of the PDF.

    (read your newsletter)

      1. Just set my 2018 goals and one of them is to actually stick to a blog schedule…sounds so much easier than it is to do. I have over 10 “drafts” that are half done. What do you do to ensure you blog on schedule? Everytime I blog it generates traffic. Oddly enough my highest traffic post is about “hacking” Panera’s wifi limit…not exactly the relevant traffic I want, LOL.

        1. Hi Sean:

          I have blogged less this last year than I did in years prior, but tried to go into more depth on each page when I did. I agree with you that the more content you have out there, the better chance you will have to gain traffic and back links. Even if it is for something like hacking Panera’s wifi system, those types of articles can sometimes gain back links, which is always useful.

          I feel you on getting traffic for things that you don’t necessarily want to be know for. The best advice I can give is focus on the content that you want customers and Google to know you for.

          Teach everything you know, write for the audience you want to have, and set aside a designated time to write.

          These three things make a difference. Remember that Smek Digital is also a client, and creating content for your own company should also be a priority.

  2. I tried this solution, trying got redirect
    http://degrevelingen.nl/stacaravans-en-chalets/wp-content/uploads/sites/2/2016/02/prijslijst-duocar2016.pdf

    to

    http://degrevelingen.nl/stacaravans-en-chalets/wp-content/uploads/sites/2/2017/11/prijslijst-duocar2018.pdf

    But instead I get a blanco page, as you can see. Any idea’s why it doesn’t work? It’s not that .php doesn’t work in this folder (I tested it). The ‘Header’ info shows up in the source of the page.

    1. Hi Leon:

      Yes, this page tells you how to redirect a PDF to a page. Since servers by default will show a PDF. But I think this problem can be approached in a different manner.

      Normally, you would want to redirect a PDF if you want to preserve back links to the PDF, and send them to a dedicated page. If the new PDF is linked from the site, Google will crawl and index that PDF on it’s normal schedule.

      But it appears that in this case, you are updating the chalet price list from the 2016 to the 2018 prices. I didn’t see any external back links to the old PDF in Ahrefs, though you may be aware of external links that I don’t know about. Or the site may have sent out an email list with a link to the old PDF recently.

      Since it doesn’t look like there are back links that we are trying to preserve, and Google will index the new PDF once it is linked from the site, here is what I would do instead.

      1) Get a copy of the 2018 PDF, rename it to the old PDF name.
      2) SFTP to the original 2016 PDF, and rename the PDF with 2016-old.pdf, or whatever you would like.
      3) SFTP the 2018 PDF to the uploads folder in the appropriate spot. This effectively replaces the old PDF, eliminating the need for a complicated 301 redirect.

      I’m presuming there’s a fringe case in play here, where the old PDF is linked somewhere that I don’t know about. On the site, you can add the 2018 PDF with it’s original name, and link to it on the applicable page.

      At least, this is how I would handle it. More efficient.

      Hope this helps,
      John

  3. Hi John,

    Thanks for your answers. I was indeed under the impression this trick would work for pdf to pdf too, you’re right.

    You’re also right that the old url I mentioned isn’t used on the website any more, nor on newsletters etc. It *does* however show up as one of the top results when I search Google for ‘prijslijst duocar’ (Dutch for ‘pricelist duocar’ = on of the brandnames on the site). So that’s why I wanted to fix this old link.

    It would probably be fixed by Google’s crawl-bots sooner or later but I was getting impatient since this was taking over a 10 days now.

    Personally, I would prefer to put all pdf’s in a /downloads folder, outside of wordpress, but my client isn’t comfortable using FTP so I’m trying to keep things as simple as possible for him. It’s not complex of course but for someone who only changes the pdf’s once a year it will never become a regular chore of course.

    Meanwhile, I fixed it via a 301 redirect line in .htaccess, that works fine of course and is just as fast as replacing old pdf’s with new ones with the old names.

    Afterthought: Aren’t you afraid Google frowns upon the ‘switch old pdf for new with old name’ approach?

    1. Hi Leon:

      I understand your confusion as to why this wouldn’t do a PDF to PDF redirect. Originally, I put this together after needing a PDF to page redirect. I had not even considered PDF to PDF as a need.

      Right now, I’m still seeing the Google index has the 2016 PDF showing up. After hearing more about your situation, I can see why you’d be impatient at the changeover. Google may not crawl that site often enough, and may crawl the PDFs even less frequently than the regular pages.

      Whenever I’m trying to get a new version of a page or document indexed, I go to Search Console and use Fetch and Render, then Request indexing as a way to speed things up.

      Your last question is a fair one. Would Google frown on changing a document at the same URL? In this case, the information seems like it would be very similar — the only things being updated are the year and the pricing, so it wouldn’t be a drastic shift.

      Now that I’ve heard more about your situation, I would say this: Google would normally still have had the old PDF indexed, so the .htaccess solution was the best choice. (Otherwise, it would have had both the 2016 and 2018 PDFs in the index eventually).

      Thanks again,
      John

      1. Interesting to hear your thoughts on this, thanks again. I found that there were some more broken links and some no longer accurately priced pdf’s on the site, so I redirected those too.

        You might want to delete the urls I gave in my first post for a non-hyperlinked / simplified version because within a year the new pdf will be replaced or redirected and the old one is already a ‘301’ permanent redirect. Bad for your SEO 😉

Join the Conversation

Your email address will be kept private. Required fields marked *.