• Resolved SJNBham

    (@sjnbham)


    Is there a way to append a query string parameter to all PDF requests on a site?

    Something like this:

    Source URL (regex): ^(\/)(wp-content\/uploads\/.*\.[pP][dD][fF])$
    Match: URL only
    Target URL: /$2?ver=[unixtime]

    We’re trying to figure out how to force fresh downloads of PDFs on our site every time. We often reuse the same file name to avoid having to update links to 3rd party sites, but want to ensure the latest version of the PDF is delivered.

    When we try the redirect rule above, it doesn’t appear to do anything. Nothing appears to be logged when we try to access a PDF on the site.

    We have another redirect rule that basically provides a short URL for all of our PDFs in our media library and it appears to be working correctly. The redirect activity is being logged as well:

    Source URL (regex): ^(\/[a-zA-Z-_\d]+\.[pP][dD][fF])
    Match: URL only
    Target URL: /wp-content/uploads$1

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

    (@sjnbham)

    Two other updates.

    1) This appears to work just fine (results in redirecting and appending the unix timestamp as a query string:

    Source URL (regex): ^(\/[a-zA-Z-_\d]+\.[pP][dD][fF])
    Match: URL only
    Target URL: /wp-content/uploads$1?ver=[unixtime]

    So /2021-06-24-staff-report.pdf becomes /wp-content/uploads/2021-06-24-staff-report.pdf?ver=1641862689

    2) We’re wondering if having two redirection rules that affect the same URL for a PDF would cause an issue (double-hop redirect for a PDF). But in any case, the following doesn’t appear to be working:

    Source URL (regex): ^\/(wp-content\/uploads\/.*\.[pP][dD][fF])$
    Match: URL only
    Target URL: /$1?ver=[unixtime]

    So /wp-content/uploads/2021-06-24-staff-report.pdf doesn’t get modified by the above rule.

    Plugin Author John Godley

    (@johnny5)

    Only one redirect rule can take place at a time.

    I don’t think you can really use a redirect for cache bust something. If someone has a URL cached then they won’t request the URL again and so it will have no effect.

    Thread Starter SJNBham

    (@sjnbham)

    Hi @johnny5 – thanks for the reply. We’re still unsure why the first rule wasn’t working while the second rule was. But in any case, we resolved this by working with our WordPress hosting provider to update the server config to insert a header for all PDFs of cache-control: no-store. Seems to be working well and avoids confusion from the version query string being appended to the file name.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Redirect rule to cache bust for PDFs’ is closed to new replies.