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.

4 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.

Join the Conversation

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