Support » Networking WordPress » Firefox can't open PDF links from WordPress multi-site

  • Resolved ssj_costy



    I have a WordPress multi-site, and my problem is that Firefox can’t open any of the PDFs that I have there. I get a dark-gray screen and it says “This PDF document might not be displayed correctly”, but I am able to download it. In .htaccess I have this rewrite rule for files:
    `RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]

    The thing is that if I write the actual path to the file it opens it in preview just fine. Also, Chrome and IE don’t have this problem.

    Best regards

Viewing 15 replies - 1 through 15 (of 15 total)
  • Firefox probably doesn’t like how PHP is parsing it.

    Best Option: Just link directly and not via /files/

    Second Best: Stop using /files/ and switch to the uploads folder, though it’s not easy.

    Isn’t there a way to maybe change some WordPress settings so that PHP will parse it differently? Because I can’t really change the links at this point.

    I’d be interested in seeing this for myself. Can you post an actual link that doesn’t work?

    This doesn’t get opened in the browser:

    This does:

    And it is the same file, the only difference is that for the 1st I am using the rewritten URL.

    Isn’t there a way to maybe change some WordPress settings so that PHP will parse it differently? Because I can’t really change the links at this point.

    No, it’s not WP it’s your browser. works for me on Firefox 24 by the way…. Do you have Adobe Acrobat Reader installed?

    And yes you CAN change links. It’s called editing the posts 🙂 Use .htaccess to redirect the older ones.

    The first one is broken for me in Firefox 24 using the “Preview in Firefox” setting, but it works in an external viewer. The second one works both ways.

    The two links send different HTTP response headers. The Accept-Ranges header is missing from the one that fails, and I see that there’s discussion of this header and also Content-Disposition in other forums in relation to PDFs, but I haven’t delved into the details.

    It’s weird, I was able to get both to work in FF. Maybe mine’s set to be more forgiving to headers?

    Are you getting the black screen? That looks like it goes back a while with Firefox:

    Well ok, I will do some research on the response headers, maybe I can patch it up somehow. I will post back the solution if I find it.

    Yes, I get the black screen.

    On downloading both versions, I see that the first one has two linefeeds at the start. It is not a strictly valid PDF file, but evidently some viewers are tolerant of this.

    The second one starts correctly %PDF-1.6 and it has a harmless carriage return and linefeed at the end, making it exactly the same length as the broken one.

    I can reproduce the problem with a different PDF. I linearized it, removed the final CRLF, and added two LFs at the start. The resulting file opens in an external viewer but causes the black screen in Firefox preview.

    *sigh* Stupid Firefox.

    Really since WP has dropped ms-files for new installs of WP, I would do this:

    Get rid of using it :/

    I wonder why that is, since both urls point to the exact same file.

    It’s not easy for me to drop “ms-files”, because of some issues… The client’s hosting plan doesn’t allow ftp access to the files created by WordPress for some reason, so it will be really hard to move them. And the other thing is that we already have thousands of files (images and pdfs).

    I’m still searching for some kind of workaround.

    Do you have SSH access? WAY faster.

    The options are these:

    1) Change the links to direct links
    2) Get rid of MS files

    I wish I had a better answer, but it’s pretty clear that Firefox + your server’s handling of PDF via PHP isn’t working, and your only OTHER option would be to write a plugin that would detect if a file was a pdf and, if so, insert headers. Which would be very custom work.

    I ended up following your advice and got rid of ms-files. Followed the tutorial you mentioned (, spent quite a while making sure I replaced all kinds of filepath strings in the DB and it all ended up working perfectly!

    Thanks a lot for the help guys 🙂

    And I used a File Browser plugin to move the files.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘Firefox can't open PDF links from WordPress multi-site’ is closed to new replies.