Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: OpenID Connect / OAuth client 3.0.0-alpha9 New alpha version released for module openid_connect (3.0.0-alpha9). Usage Milestone: Google Analytics Module google_analytics crossed 1,000 active installs. Release: Timelinr 1.0.1 Minor update available for module timelinr (1.0.1). Release: GraphQL Compose Codegen 1.1.2 Minor update available for module graphql_compose_codegen (1.1.2). Release: Mapy.com 1.1.3 Minor update available for module mapycom (1.1.3). Release: Ckeditor5 entity browser 3.0.3 Minor update available for module ckeditor5_entity_browser (3.0.3). Release: Ckeditor5 entity browser 3.0.1 Minor update available for module ckeditor5_entity_browser (3.0.1). Release: Ckeditor5 entity browser 3.0.2 Minor update available for module ckeditor5_entity_browser (3.0.2). Release: Teamleader Integration 4.0.2 Minor update available for module teamleader (4.0.2). Module Revived: Entityqueue Buttons 1.1.2 Module entityqueue_buttons updated after 8 months of inactivity (1.1.2).

Media Entity File Redirect

704 sites Security covered Drupal 9–11
View on drupal.org

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

Depends on

Dependencies of the latest stable release

  • media Drupal core

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

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

Releases

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