Blog: SEO
Light up Arrows pointing right

How To 301 Redirect a PDF in WordPress for SEO

Avatar for John Locke

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

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

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:" );

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, the new path is, 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 a SEO consultant from Sacramento, CA. He helps manufacturing businesses rank higher through his web agency, Lockedown SEO.

32 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. Hi Sean:

      Good to see you in the comments again! What you are describing is exactly what we had to do for this client. Hope your 2018 is off to a great start.

      – John

      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


    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,

  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,

      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 😉

    2. Hey Leon,

      I’m trying to do the same with a .htaccess line, but it just isn’t working and I’m frustrated. Any idea what could be the reason?

      Could you let me know exactly how / where you placed the redirect line in .htaccess, or does it really matter?

          1. Hi Leon:

            I changed my preceding comment for clarification.

            It’s possible that I’m completely wrong here, but I don’t think you can do a .htaccess 301 of a PDF to PDF on all servers.

            I just did a sanity check on several different environments to make sure. The 301 .htaccess PDF to new PDF tests I did wouldn’t forward the old PDF to the new one.

            For Narayan, he may want to check with his hosting provider to make sure the environment supports a PDF to PDF 301 via .htaccess.

            I know that you were able to do it, so obviously it is possible. I don’t know what Narayan’s hosting setup is, so that might be the part of the issue.


        1. Still, you have a point / it’s worth mentioning that apparently, redirects may not work for different file extensions, like for .pdf in this case.

          I tried a wordpress plugin for it and it didn’t work on .pdf’s. Not sure what hosting etc it was.

      1. I’m no .htaccess expert but I have the redirects right after the RewriteEngine rules. You need those first, if I remember correctly. I have them before the other rules that WordPress uses, because else the request is handled by WordPress (I think) before it reaches the redirect-pdf-rule.

        RewriteEngine On
        RewriteBase /
        RewriteRule ^index\.php$ - [L]
        #redirects dode links 180227 gemaakt:
        Redirect 301 /wordpress/wp-content/uploads/sites/2/2016/02/prijslijst-duocar2016.pdf/
  4. Hi
    Thanks for the guide, it has helped me a bunch of times.
    I just ran into a problem with a site that used to have lots of pdf’s with spaces in their filenames. I use htaccess to redirect but it does not allow space or “%20”.
    Anybody got a solution to that?
    Best regards,

      1. Thanks for the link, I tried the Regex, but failed, it’s the right way to do it on a large scale but I’m no wizard aswell 🙂
        I managed to fix it with double quotation marks.
        So the redirect looks like this:
        Redirect 301 “ is a.pdf”

  5. Hi folks, I ‘ve just applied the original method indicated in the post and it works fine. "figuras geometricas para armar e imprimir pdf"

    And click in the PDF.

    You’ll see that redirect to my landing page.

    So…thanks for the post, I’ve fixed a problem with my traffic!

  6. Hi John. Thanks for the cool explanation about redirects.
    I’ll tell you my case.
    I moved the site to a new domain (sites are completely identical), set 301 redirects on the old domain through a file .htaccess.
    Everything was fine, but today I noticed that the google search contains pdf files from the old domain, to which the redirect did not apply.
    I started looking for a solution to this problem and found this thread.

    I have a server, if I understand correctly on Apache and the easy redirect method did not help me. I tried the second method with PHP. I renamed the pdf file, created a folder with the original name of the pdf file, created an index.php and wrote the desired link. But there’s a problem.

    For example, I want to redirect from this pdf file – to this page –

    Process video –

    And after all manipulations we have redirect to this

    I would be satisfied with this redirect, since there is a pdf file on the same path on the new site, but due to the “/” sign at the end of the link, the link gives an error.

    Perhaps there is some reasoning about this? I would really appreciate your help.

    1. Hi Denys:

      It looks like your server is using nginx, and I don’t know if that’s a layer on top of Apache (some hosts do that here). But that explains why .htaccess did not work.

      From what is sounds like, the server is set up to add the trailing slash on URLs, so that is getting appended to the PDF redirect and causing a 404.

      your best bet would be to reach out to your hosting company and see if they can help you with that server configuration. Normally the behavior you are describing shouldn’t happen with the URLs.


    1. You should be able to redirect a PDF to the home page. But if you have another page that is similar to the PDF, that would be better.

      It may be “easier” to redirect deleted pages to the home page, but Google will compare the old content (old PDF) to the new content (redirect target). The closer the content and subject matter, the better.

      – John

  7. Hello, the hosting service I use for my WordPress site provides the ability to create a redirect within the hosting dashboard. Would creating the redirect this way be sufficient for seo purposes? I would like to redirect an outdated PDF that is indexed and ranking to another page that has similar content that I plan on updating. Thank you for this article informative article because I want to make sure I do the redirect properly.

    1. HI Michael:

      As long as the redirect is a 301, and it works successfully, you should be fine. You can see if the original page redirects by using Dev Tools in your browser, by looking for HTTP request headers.

      Open the webpage whose headers will be redirected to your destination page (or PDF).
      1. Right click and select ‘Inspect’ to open developer tools.
      2. Select the network tab and refresh or reload the page.
      3. Select any HTTP request from the left panel and the header will be displayed on the right.

      What you’re looking for is displayed in the screenshot below, on the right hand column.

      HTTP headers displayed in Dev tools

      In this case, this is the browser showing a 301 redirect from to .

      PDFs are somewhat trickier to redirect vs traditional web pages, so that’s why I published this tutorial originally.

      – John

Join the Conversation

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