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
CodePudding user response:
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
CodePudding user response:
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 .