Drupal is a registered trademark of Dries Buytaert
Protected Pages 3.0.0 Major update available for module protected_pages (3.0.0). Commerce Core 3.3.8 Minor update available for module commerce (3.3.8). Search API HTML Element Filter 1.0.7 Minor update available for module search_api_html_element_filter (1.0.7). Layout Builder Reorder 2.0.1 Minor update available for module layout_builder_reorder (2.0.1). Ban 1.1.0 Minor update available for module ban (1.1.0). Field Formatter Range 2.0.0 Major update available for module field_formatter_range (2.0.0). Field Formatter Range 8.x-1.8 Minor update available for module field_formatter_range (8.x-1.8). UI Patterns (SDC in Drupal UI) 2.0.18 Minor update available for module ui_patterns (2.0.18). Search API Solr 4.3.11 Module search_api_solr updated after 14 months of inactivity (4.3.11). Provus Mega Menu Module provus_mega_menu crossed 1,000 active installs.

This module provides a persistent redirect path for file-based media entities, allowing you to link to a stable URL that always points to the latest version of the file. It also integrates with LinkIt for easier link creation.

Overview

This simple modules provides a new path /document/[id] which redirects to the file source of a media entity.

For many media entities with file sources (like a "Document" media entity), you typically want to link users directly to the file source path. However, it's not considered a good practice to link to this direct path because if the file is replaced with a new one, the path with change, even if you upload a replacement file with the same name.

This module works around that problem by providing a new path /document/[id], where [id] id the ID of the media entity. Requests to this path will redirect to the actual file source path.

This allows you to "hide" the real file path in your links. If you ever need to replace the file upload with a new one, you don't need to worry about updating any links to that file.

This module also provides support for LinkIt, allowing you to create these /document/[id] links directly in CKEditor.

Setup/Configuration

After this module is enabled, edit one of your existing media types that uses a file or image source field. You will see a checkbox "Expose access to file source via path /document/[id]" to enable the behavior for all media entities of that type.

LinkIt

This module ships with LinkIt "Matcher" called "Media: File Redirect". This is identical to the normal "Media" matcher, with two key differences:

  1. If you have canonical paths for media entities disabled, this matcher still works, whereas the normal "Media" matcher does not
  2. The URL that's returned by the LinkIt search field is /document/[id] instead of /media/[id]. Even if you have canonical paths enabled for media entities, this is helpful because it won't confuse your editors to see the /media/[id] path (many do not consider a file or document to be "media").

Similar Modules

The Media Entity File Replace module allows editors to replace files and overwrite the original filename, thus negating the need to obscure the real path of the file.

The Media Entity Download module does something similar to Media Entity File Replace. It creates a dedicated "download" path, /media/[id]/download, which returns the file source as a direct download instead of redirecting to the file source URL.

The downside to such an approach is that Drupal acts as a proxy for serving up file assets, which takes up PHP resources. That may not be a big deal if there are not many documents and they are not extremely popular to download. It also forces your browser to download the file instead of possibly opening it directly in your browser

Activity

Total releases
2
First release
Dec 2024
Latest release
1 year ago
Releases (12 mo)
0 ▼ from 2
Maintenance
Dormant

Releases

Version Type Release date
8.x-1.2 Stable Feb 3, 2025
8.x-1.1 Stable Dec 10, 2024