• Hello,

    Whenever I attempt to download the PDF that I have uploaded with WP Document Revisions, it will give me a 404 error. If I turn the permalinks setting to Plain, then it will allow me to download the PDF. If I turn the permalinks back to Post name, then it will go back to the 404 error.

    I have looked at some of the other threads and adding a / to the end of the .pdf manually doesnt help: “filename.pdf/” still gives a 404.

    The problem only occurs with .PDF
    .DOC, .XLXS and .PPTX seem to work fine.

    Any ideas on what I can do to make it work with nice permalinks? Perhaps it is an issue with something outside of the plugin because it works with other extensions.

    Thanks!

Viewing 1 replies (of 1 total)
  • Thread Starter ABarBot

    (@abarbot)

    Update: If you don’t mind ugly permalinks on your wp-document-revision urls, then this crude fix will work. In my case, if you set the permalinks settings to “Plain”, then the .pdf will open correctly without a 404 error. This makes the permalinks ugly for the rest of the website. My solution was to modify the file at “/wp-content/plugins/wp-document-revisions/includes/class-wp-document-revisions.php”.

    Starts at Line 596. This is my exact code. I commented out the original code.
    ______________________________________________________________________________
    // if no permastruct
    if ( ” === $wp_rewrite->permalink_structure || in_array( $document->post_status, array( ‘pending’, ‘draft’ ), true ) ) {
    $link = site_url( ‘?post_type=document&p=’ . $document->ID );
    if ( $revision_num ) {
    $link = add_query_arg( ‘revision’, $revision_num, $link );
    }
    return apply_filters( ‘document_permalink’, $link, $document );
    }
    $link = site_url( ‘?post_type=document&p=’ . $document->ID );
    if ( $revision_num ) {
    $link = add_query_arg( ‘revision’, $revision_num, $link );
    }
    return apply_filters( ‘document_permalink’, $link, $document );
    // build documents/yyyy/mm/slug
    //$extension = $this->get_file_type( $document );

    //$timestamp = strtotime( $document->post_date );
    //$link = home_url() . ‘/’ . $this->document_slug() . ‘/’ . date( ‘Y’, $timestamp ) . ‘/’ . date( ‘m’, $timestamp ) . ‘/’;
    //$link .= ( $leavename ) ? ‘%document%’ : $document->post_name;
    //$link .= $extension;

    //$link = apply_filters( ‘document_permalink’, $link, $document );

    //return $link;
    }
    __________________________________________________________________________________

    Doing this forced the ugly permalink only on my documents that I posted, which allowed me to keep my WordPress permalink settings on “Post name”. It’s ugly, but it works.

Viewing 1 replies (of 1 total)
  • The topic ‘PDF and 404’ is closed to new replies.