• Resolved satsoklgr

    (@satsoklgr)


    There are more problems arising, its not the plugin’s fault, but the way my site works that makes it unusable.

    I have more than 20.000 photos, I must redirect each URL of them to the parent post, I don’t like the Yoast option that redirects the image URLs to the file itself.
    So, I left the yoast redirection deactivated and use instead this code in image.php
    <?php wp_redirect( get_permalink( $post->post_parent ), 301 ); exit; ?> to do the redirection to parent post.

    But, here the funny behavior starts.

    For every attachment URL, the cache enabler creates a separate cache file with the name of the image inside every post’s folder.
    If I try to reload the same image to check the redirection or the header’s status, a white page is loading.
    This is normal as the created file is not complete as I see.

    Must be a way to tell the plugin not to cache the redirections, but only the destination URLs.

    By the time plugin is deactivated until a solution is found.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter satsoklgr

    (@satsoklgr)

    Found the solution.

    Instead of the image.php method to redirect attachments, I use a function in child’s theme “functions.php”

    I write it in case someone faces the same problem.

    add_action( 'template_redirect', 'wpsites_attachment_redirect' );
    function wpsites_attachment_redirect(){
    global $post;
    if ( is_attachment() && isset($post->post_parent) && is_numeric($post->post_parent) && ($post->post_parent != 0) ) :
        wp_redirect( get_permalink( $post->post_parent ), 301 );
        exit();
        wp_reset_postdata();
        endif;
    }

    Put it at the end of functions.php just before the closing ?>
    This way, cache files for redirected attachments are not created anymore!

    • This reply was modified 4 years, 3 months ago by satsoklgr.
    • This reply was modified 4 years, 3 months ago by satsoklgr.
    Anonymous User 16850768

    (@anonymized-16850768)

    I’m glad to hear you’ve fixed this for your use case. Just so you’re aware, the Cache Enabler plugin won’t cache a 301 status code. This means it’s possible the page in discussion was previously being cached before the redirect you’ve created was being set. However, with the information I have available I can’t say for certain what occurred.

    Thread Starter satsoklgr

    (@satsoklgr)

    I don’t know, I only reported what I noticed, maybe the first way was calling first the page and then redirect it.
    The function action justs redirects so it is not cached.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How not to cache redirections?’ is closed to new replies.