Is it possible to create a redirect for documents using the Redirect module? I can't seem to find a solid answer. Basically I'm just trying to create a redirect from https://www.example.com/default/files/2022-05/map.pdf to https://www.example.com/default/files/2022-10/map.pdf.

If this isn't possible, what would be a good recommendation other than modifying .htaccess as this is something that people without access or knowledge of .htaccess will need to use.

  • 1
    Welcome to Drupal Answers! You asked if you can redirect documents with "this module" but you did not specify which module. I assume drupal.org/project/redirect but let's be certain. This is maybe what you mean by "Drupal Redirect" in the question title. Probably.
    – mona lisa
    Commented Oct 19, 2022 at 19:09
  • 1
    When some person accesses site.com/default/files/2022-05/map.pdf there's no Drupal involved. So, of course this redirect created in Drupal isn't working. It might be possible if you create a new node/page that has the URL alias of /default/files/2022-05/map.pdf and maybe also delete the actual file /default/files/2022-05/map.pdf that it might work.
    – leymannx
    Commented Oct 19, 2022 at 19:18
  • @cilefen thanks for the heads up on that. I edited my original post to reflect the module I am using.
    – divspan
    Commented Oct 19, 2022 at 20:22
  • @leymanxx I think I'm going to give this a shot just to see if it actually works.
    – divspan
    Commented Oct 19, 2022 at 20:22

2 Answers 2


As @leymannx commented, the public file folder is not controlled by Drupal, it is delivered directly through the web server.

Move the file to the private file system. Then Drupal can control access to the file and also redirect if you want.

  • This makes total sense, and I can't believe I didn't catch it! Thank you very much!
    – divspan
    Commented Oct 19, 2022 at 20:19

Using the private file system as described by @4uk4 is the correct way to secure the files and ensure only the correct users have access.

In addition to this, if you want to improve the convenience of managing files for site administrations (and perhaps users), you can use media entities.

This is more work for the developer to set up but it can standardize processes and make life easier for admins/users.

When you enable the core Media module, a File media entity type is created by default. You can customize this media type by adding additional fields, or you can just use the File media type as is.

When you do it this way:

  • You need to create a File media entity for each file.
  • To attach files to nodes, instead of a File field that stores the file directly, you use an Entity Reference field to the File media entity type.

As you can see, this adds some additional steps. But, then you get the following benefits:

  • Each file has its own entity, so if you need the same file in multiple places, you can link it via entity reference instead of uploading it multiple times.
  • You can easily sort files in Views and make views that show files based on various attributes.
  • Media entities can store file metadata in fields, which can be filtered in views.
  • The media entities can be themed and treated as "pages" (given URLs), so for example you could embed the pdf on the page or customize the download link to add whatever legal disclaimers you need.
  • We're using the media module and all of the files in the media tab are indeed in the /media directory. It looks like when someone deletes the file it removes the media entity, but the original file is still listed in the file tab. I've updated the settings.php to allow deleted files to marked as temporary, but there is still the issue that it isn't regressive. I've looked into the file delete module, but since we're using revision history it isn't an option. I believe I'm going to try FFdelete tomorrow to see if I can rid the orphaned files. Thanks for the great explanation!
    – divspan
    Commented Oct 20, 2022 at 20:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.