deindex_unpublished_files
The Deindex Unpublished Files module ensures that files associated with unpublished media are not publicly accessible. It achieves this either by adding a prefix to the file URL or by moving the file to the private files directory (private://unpublishedfiles), helping protect unpublished files from being exposed or indexed by search engines.
The module functions only with media types that include a file field.
It also provides a "Unpublish media by usage page" at /admin/content/deindex-unpublished-files/unpublished-media that lists media usage (unpublished nodes, published nodes, and other entities) to help identify items that should be unpublished. Rows highlighted in light red indicate media that is only used in unpublished content.
Installation
Place the deindex_unpublished_files module folder into modules/contrib.
Clear Drupal caches if necessary.
Visit the configuration form at:
Configuration → Media → Unpublished files settings (if the module is enabled).
Configuration
Choose the method to make unpublished media files inaccessible:
Prefix method: Adds a URL prefix to prevent access.
Private files method: Moves the file to a private directory (private://unpublishedfiles).