Prevent domain added to file URL

Created on 30 August 2024, 5 months ago

Problem/Motivation

A content type with a file field and a view is used to list this content's title along with any attached files.
These files are shown as generic files in the view.

In the view preview [so going through the admin theme], the file URL is /sites/default/files/path-to-file

On the front end this link becomes https://domain.com/sites/default/files/path-to-file
both in the view and the node.

The front end template used is: web/themes/contrib/bootstrap/templates/file/file-link.html.twig

When the Internal Page Cache is enabled, the domain element is created based on the domain accessed to create the cache.
If the domain was accessed on http, then the cached link becomes http. The major issue is that this site can be accessed via an IP address as well, and when the cache includes the ip, the site owner is unable to access these file links.

How can I remove the domain element of the generated URL?

I appreciate the specific problem can be resolved by enforcing the incoming traffic to only use a single domain & protocol, this will require getting the hosting company to adjust their config to enforce https, deal with IP access and so on which will take some time.

Steps to reproduce

Create a file field on content type. Create some content, include a file and save. Inspect the file link and the domain will be part of the url.

💬 Support request
Status

Active

Version

3.32

Component

Templates

Created by

🇬🇧United Kingdom ice70

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024