Invalid media and asset URL

See Media URL on multisite with domain mapping · Issue #325 · roots/bedrock · GitHub for initial issue
It was suggested that I post here.
Here’s the config I use taken straight from documentation

/* Multisite */
define('WP_ALLOW_MULTISITE', true);
define('MULTISITE', true);
define('SUBDOMAIN_INSTALL', true); // Set to true if using subdomains
define('DOMAIN_CURRENT_SITE', env('DOMAIN_CURRENT_SITE'));
define('PATH_CURRENT_SITE', env('PATH_CURRENT_SITE') ?: '/');
define('SITE_ID_CURRENT_SITE', env('SITE_ID_CURRENT_SITE') ?: 1);
define('BLOG_ID_CURRENT_SITE', env('BLOG_ID_CURRENT_SITE') ?: 1);

and here’s the relatevant secition from the .env file

DOMAIN_CURRENT_SITE='mysite.local'
WP_ENV='development'
WP_HOME='http://mysite.local'
WP_SITEURL='http://mysite.local/wp'

I’m creating a network site on subdomain demo.mysite.local

The assets on demo.mysite.local are referring to mysite.local
For example instead of
http://demo.mysite.local/wp/app/themes/mytheme/app.js
i’m getting
http://mysite.local/wp/app/themes/mytheme/app.js

How do I make the asset base domain url to correspond to site domain?

2 Likes

Is there any update on this?

Hello all!
I found a solution based on removing the vars definition from ENV and passing to the application file which is php and can get the domain.

The function is:

function siteURL(){
    $protocol = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? "https://" : "http://";
    $domainName = $_SERVER['HTTP_HOST'].'';
    return $protocol.$domainName;
}

and then:

/**
 * URLs
 */
Config::define('WP_HOME', siteURL());
Config::define('WP_SITEURL', siteURL() . '/wp');

and

Config::define('DOMAIN_CURRENT_SITE', str_replace("https://", "",siteURL()));

The unique problem is that this also changes the network admin url on the “non-main domains” but to update plugins and everything you can do it accessing from the main domain.

Not a huge issue.

Hope it helps to anyone :slight_smile:

Bests!