skip to Main Content

I would like to add a 301 redirect when users visit a specific page and redirect them to a PDF file.

In my .htaccess file I tried something like this this but it gives me a 404 error. However if I visit the path, the PDF it’s there

Redirect 301 /subpage https://www.mywebsite/upload/files/file.pdf

What am I doing wrong?

PS: I am using WordPress

3

Answers


  1. To target an HTML link to a specific page in a PDF file, add #page=[page number] to the end of the link’s URL.

    For example, this HTML tag opens page 4 of a PDF file named myfile.pdf:

    <A HREF="http://www.example.com/myfile.pdf#page=4">
    

    And If you want to redirect a single page to another you just need to insert this line in the .htaccess file:

    Redirect 301 /old-post https://www.yourwebsite.com/myfiles/myfile.pdf
    Going to replace the old and new addresses respectively.

    The code must be inserted after and before .

    Login or Signup to reply.
  2. Redirect in htaccess does not matter if it is a pdf file or anything else just a valid link.
    This is an example of a 301 redirect code to the link you want

    RedirectMatch 301 /subpage/ https://www.mywebsite.com/upload/files/file.pdf

    Login or Signup to reply.
  3. You are getting a 404 probably because the URI /subpage doesn’t exist or map to an existent file. The Redirect you are using doesn’t redirect the /subpage to the PDF location because your WordPress RewriteRules override it. If you want to fix it , you will need to use RewriteRule directive instead of Redirect at the top of your htaccess :

    RewriteEngine On
    RewriteRule ^/?subpage/? https://www.mywebsite.com/upload/files/file.pdf [R=301,L]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search