WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] File Upload, Link, Error 404 (10 posts)

  1. niko82
    Member
    Posted 4 years ago #

    Hi All, I'm quite stumped here. I've searched around the web and the wordpress forums to no avail.

    Here's the problem: I upload a .pdf file using the media library. And link to it from a page or post. But when I follow the link I get a 404. When I try to Save Link As... it downloads but then I can't open it says it's corrupted.

    So I login to FTP the check it out. The file is there and is intact (i.e. not corrupted). Weird.

    One user suggested uploading the file into the root via ftp and linking to it there. Not a permanent fix but just for arguments sake I tried it, and I still get a 404.

    The page I'm working on is here: http://www.gapacc.ns.ca

    The file in question can be found here: http://www.gapacc.ns.ca/wp-content/uploads/membership_form.pdf

    Which is linked to on this page: http://www.gapacc.ns.ca/join-gapacc

    After reading some previous responses to similar problems here's some answers to likely questions:

    I know how to link to a file using Add Media and a href tags so this is definitely not the problem.

    Uploads are set to: wp-content/uploads. Organize by Month is NOT ticked.

    Permalink custom structure is set to: /%postname%/

    Could this be a permissions thing? .htaccess can be changed through PLESK but is not writable through the dashboard.

    I sincerely look forward to any help with this. I'm seriously stumped. This seems like a really basic issue and I'm frustrated I can't figure it out.

  2. esmi
    Forum Moderator
    Posted 4 years ago #

    The file in question can be found here: http://www.gapacc.ns.ca/wp-content/uploads/membership_form.pdf

    Umm... no it's not. 404.

    Can you try resetting your permalinks back to the default structure and see if that helps?

  3. niko82
    Member
    Posted 4 years ago #

    Hey thanks for the quick reply!

    Yeah that's the problem I get a 404. But the files there. I can access it through FTP.

    I just reset the permalinks same problem.

    Any other ideas??

  4. niko82
    Member
    Posted 4 years ago #

    Really strange, it seems like everything is sorted. Is it posible it's a permissions issue that's preventing links to files from working??

  5. niko82
    Member
    Posted 4 years ago #

    Has anyone else ever had the problem of files not linking properly??

  6. esmi
    Forum Moderator
    Posted 4 years ago #

    I think you ran into a rewrite problem - a not uncommon issue when you use a custom permalink problem such as /%postname%/. http://codex.wordpress.org/Using_Permalinks does explain why this isn't a good choice.

  7. niko82
    Member
    Posted 4 years ago #

    Thanks esmi, Funny you should mention this now because I just got it sorted.

    See my post re this issue: http://wordpress.org/support/topic/357445?replies=10

    For me, the problem was related to permalinks and the .htaccess file which was calling for a 404 error page instead of accessing the file. So wordpress -- or at least a faulty .htaccess -- was effectively "blocking" access to files. After a long talk with tech support at the site host, and looking through error logs, trying a few things here and there, we determined it was indeed the .htaccess file.

    So I deleted the .htaccess file after removing permalink settings and the files loaded. But this caused a few other issues with pages not being found etc. So rewrote the .htaccess file (see below).

    Plus, the .htaccess file is what's responsible for generating the 404 error page in the first place which I didn't know and would have helped me narrow down the problem in the first place. Here's a good link re .htaccess: http://www.freewebmasterhelp.com/tutorials/htaccess/

    So here, from the codex, I think is the root of the problem:

    Using only %postname%

    If using version 2.0 or greater, the following is no longer true as this has been changed.

    If you use postname as the only element in your permalinks to create a structure such as example.com/post-title, the rewrite rules may make it impossible to access pages such as your stylesheet (which has a similar format) or the /wp-admin/ folder . It's best to include some numeric data (e.g. the post ID or date) in the permalink to prevent this from happening. Additionally, WordPress v1.2.x requires the use of a date structure in order for some features, such as the calendar, to function properly. /%year%/%monthnum%/%day%/%postname%/ is always a good start.

    You can get past the above issue and continue using %postname% if you make a simple change to your .htaccess file as below:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} ^wp-content.*
    RewriteCond %{REQUEST_FILENAME} ^wp-admin.*
    RewriteCond %{REQUEST_FILENAME} ^wp-include.*
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    # END WordPress

    Simply the conditions now say do not apply the rule if the file name includes the word press content, admin or include directory. This now allows you to get to the admin area with no issues as well as content.

    Which is from the codex here: http://codex.wordpress.org/Using_Permalinks And don't say " Should've read the codex first", because I would have if I could have isolated the problem to the .htaccess file initially.

    Thing is, my .htaccess file didn't include the #BEGIN and #END WordPress. Which is my best guess as to why it was preventing access to files uploaded with Media Library.

    If you haven't changed your permalinks settings it's possible something else has tinkered with your .htaccess file and it's the same problem. So I would try rewriting it anyway. And change the permissions to 666 so wordpress can write to it afterward.

    I found a few of the images were still not working so I had to go back and reload them with media library. It worked.

    So I hoped that helps anyone else who seems to be having this problem.

    I look forward to any feedback on this issue, e.g. why exactly is it that using only /%postname%/ as your permalink structure restricts access to some files????

    Anyway all the best, keep up the good work wordpress team!

  8. craig0927
    Member
    Posted 4 years ago #

    I'm having the same problem (404 when i click on the links, but I can right click and save as with no problem).

    However, when I try adding the 3 lines below to my .htaccess, the problem is worse...I can't even access the page that files are linked on...or any other page other than the home page.

    RewriteCond %{REQUEST_FILENAME} ^wp-content.*
    RewriteCond %{REQUEST_FILENAME} ^wp-admin.*
    RewriteCond %{REQUEST_FILENAME} ^wp-include.*

    Needless to say...I'm finding the whole issue very frustrating...to the point I'm having second thoughts about the viability of WordPress as a commercial platform.

    I suspect the problem is resulting from the Super Fast and Secure .htaccess plugin rewirtes (about to confirm)...which i ended up installing along with several other security plugins after several of my WordPress blogs were hacked by some script kiddie.

    So, out of the box, my WordPress sites are so insecure that get hacked by any angry teenager with Windows XP and an internet connection. Try to tighten up security, and I can't even download a simple file.

    And from reading the above, it sounds like I'll find myself in a similar catch 22 regarding the permalink structure and SEO (with dates and crap, not SEO; without dates and crap, I run the risk of having WordPress problems).

    And I thought WordPress was supposed to be the user-friendly alternative. :-)

  9. craig0927
    Member
    Posted 4 years ago #

    ...and I'm a bonehead...it turns out to be a stale browser cache...
    why did the first 404 pop up...i don't know...why does my browser cache a 404 page...i don't know...but it works now with all of the Super Fast and Secure .htaccess mods.

  10. craig0927
    Member
    Posted 4 years ago #

    okay...maybe i'm not a bonehead afterall...the issue did, in fact, persist. The caching issue was actually working the other way around and generating a false positive.

    In the end, it was an .htaccess issue resulting from following this article: http://blogsecurity.net/wordpress/article-210607. Great article, and good advice...I just needed to add pdf to the list of extensions accessible in that directly. :-)

Topic Closed

This topic has been closed to new replies.

About this Topic