nystudio107 / retour

DEPRECATED Retour allows you to intelligently redirect legacy URLs, so that you don't lose SEO value when rebuilding & restructuring a website.
Other
168 stars 24 forks source link

PDF Redirecting #120

Closed CreateSean closed 8 months ago

CreateSean commented 8 months ago

Craft: 4.5.6.1 Retour: 4.1.13

Question

We're having some issues with redirecting pdfs with retour. Feel like it should work but it's not.. We've cleared cache multiple times as well as confirmed that the legacy pdf no longer exists in Craft or on disk anywhere.

A few questions to ensure that we're doing this correctly.

  1. How are we supposed to establish redirects for PDF files in Retour?
  2. Does it need to be Exact Match or RegMatch?
  3. Does the legacy file need to be deleted for the redirect to work?

Here is a screenshot of the exiting redirect: have removed the part circled in red - nc change. Have also changed path only to full url with the actual domain

Please advise

image

CreateSean commented 8 months ago

client has asked about this again? Is there something we're doing incorrectly?

khalwat commented 8 months ago

It's likely not working because the URLs for your PDFs are not being routed through Craft, thus Retour never even enters the mix.

This is normally how you'd want things to work, btw... you generally don't want static asset URLs to route through Craft, rather you want the web server to serve them up directly.

So you'd need to either add these redirects via your web server, or you'd need to ensure that .pdf URLs are routed through Craft.

CreateSean commented 8 months ago

It's likely not working because the URLs for your PDFs are not being routed through Craft, thus Retour never even enters the mix. The pdfs are uploaded into assets so afaik they should be routed through Craft.

khalwat commented 8 months ago

That's probably not the case, but give me a URL to one of the PDFs and we can find out

CreateSean commented 8 months ago

We deleted the redirect pdf as part of the troubleshooting, but the target pdf to arrive at still exists in Craft.

image

khalwat commented 8 months ago

Okay, in order for me to help you, I'd need to see a public URL to a PDF. Can you provide at least the now missing URL?

CreateSean commented 8 months ago

Andrew,

sorry about that

here is the missing pdf https://www.esscolab.com/uploads/files/E052r10-010522.pdf which should redirect to https://www.esscolab.com/uploads/E052r16-01032024.pdf

khalwat commented 8 months ago

So when I curl it, I get this:

❯ curl -I https://www.esscolab.com/uploads/files/E052r10-010522.pdf
HTTP/2 301
server: nginx
date: Fri, 12 Jan 2024 20:07:22 GMT
content-type: text/html; charset=UTF-8
location: https://www.esscolab.com/uploads/E052r16-01032024.pdf
x-sucuri-id: 20039
x-xss-protection: 1; mode=block
x-frame-options: SAMEORIGIN
x-content-type-options: nosniff
content-security-policy: upgrade-insecure-requests;
expires: Thu, 31 Dec 2037 23:55:55 GMT
cache-control: max-age=315360000
x-sucuri-cache: EXPIRED

So it's a 301 redirect to this location: https://www.esscolab.com/uploads/E052r16-01032024.pdf

And that location does indeed seem to be the right PDF file. If I paste that first URL into the browser, I'm redirected to the correct URL and I see the PDF.

What am I missing here?

CreateSean commented 8 months ago

Andrew,

Update from the client based on reporting that it was working for you (above response)

Yes, the redirect will typically work if someone has not previously gone to the old URL. I was really just looking for guidance on the correct way to add PDF URLs to Retour:

How are we supposed to establish redirects for PDF files in Retour? Does it need to be Exact Match or RegMatch? Does the legacy file need to be deleted for the redirect to work?

Please advise

khalwat commented 8 months ago

That sounds to me like a browser caching issue then? Try dumping the cache or shift-reloading the page or such. You could mitigate this by ensuring that PDF files are never allowed to be cached by the browser, but unless you're doing this constantly, that wouldn't be the best experience for people loading the PDFs.

To answer their questions:

  1. Yes, the legacy file must be deleted or moved for the redirect to work. Retour does nothing if the request resolves properly
  2. It can be either Exact Match or Regex Match, it depends on whether you're needing to use wildcards or not