Creating redirects for files (images) on Pantheon What is the best way to create 301 redirects on Pantheon for file?  I can create redirects for paths by placing rules in my settings.php:

switch ($_SERVER['REQUEST_URI']) {
  case '/my-path':
    header('HTTP/1.1 301 Moved Permanently');
    header('Location: http://mydoamin/my-new-path');
   exit();
}


This is the redirect I want to create:

a/b/c/document.pdf and e/f/g/document2.pdfboth should be redirected to /new/folder/document3.pdf.

Unfortunately, this won't work with files.

Here is how I test:


Create file test.txt in sites/default/files
Access sites/default/files/test.txt and verify it works
Update settings.php and add die($_SERVER['REQUEST_URI']); and verify you the get uri.


Instead of getting URI I get 404.
Thanks to Sarah at Pantheon for walking me through this.

File redirects aren't really possible using the same logic used to do PHP redirects for URLs.  Requests to files are managed by the server and don't run through settings.php (Drupal) or wp-config.php (WP).  It is not possible to intercept those like a URL served by the application.

If you were running your own nginx server you could manage this in a .conf file, but on Pantheon the nginx.conf isn't editable on a per-site basis since it's set platform-wide (https://pantheon.io/docs/platform-considerations/#nginxconf)

A workaround could be to utilize a third-party CDN like Cloudflare to create nginx-like redirects before you hit the server.