PDF redirect not working

#1118093
  • Hello, we have an issue with the redirections, other redirections are working fine but when we try to redirect one PDF file to another it’s not redirecting anything.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hello, we’re sorry to hear that you’re facing issues with the PDF redirection. To redirect attachments like PDF files to their media URLs using Rank Math, you can add a specific code snippet to your theme’s rank-math.php file. Here’s how you can do it:

    1. Navigate to Theme File Editor: Go to Appearance → Theme File Editor (for a Classic Theme) or Tools → Theme File Editor (for a Block Theme) in your WordPress admin area.

      Navigate to Theme File Editor

    2. Edit rank-math.php: From the list of files on the right, select rank-math.php and add the following code snippet:

      /**
      * Redirect Attachments to media URL
      */
      add_filter('rank_math/frontend/attachment/redirect_url', function ($redirect, $post) {
         return $post->guid;
      }, 10, 2);
    3. Update the File: Click the Update File button to save your changes.

      Add the code snippet to rank-math.php file

    After adding this code, all your attachment pages should redirect to the actual media URL of the PDF file. If you continue to experience issues, please reply to this ticket with your site URL so we can assist you further. Thank you for raising this concern!

    Sources:
    How to Redirect Attachments to the Media URL with Rank Math » Rank Math

    This is an automated reply from Rank Math Support Bot. Your ticket has been assigned to a human agent and we will get back to you shortly.

    Hello,

    Unfortunately, our plugin doesn’t support redirecting the PDF files.

    In this case, you will have to use the .htaccess file for such redirections. Here is a guide that can help:
    https://karenattfield.com/redirect-pdf-wordpress/

    Here’s how you can edit the .htaccess file using Rank Math:
    https://rankmath.com/kb/edit-htaccess/

    Please take a backup before editing your .htaccess file. Also, since it is a sensitive file, we recommend getting in touch with your web host for assistance before modifying it.

    Looking forward to helping you.

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this ticket.