I've just about finished migrating a D6 site to Backdrop CMS.  It's been a long process, but successful none the less.

I'm running into an issue with the way assets are loaded for the theme.  It diffres from Drupal's behavor of absolute paths.  Backdrop seems to load them using the full URL including the domain and protocol.

For example:

<meta charset="utf-8" />
<link rel="shortcut icon" href="http://www.domain.tld/subfolder/themes/sometheme/favicon.ico" type="image/vnd.microsoft.icon" />

<link rel="stylesheet" href="http://www.domain.tld/subfolder/sites/default/files/css/css_YInDv_rTqgPALb4zztYVH-_aoZ21p7QQhGSv6L8GybI.css" media="all" />
<link rel="stylesheet" href="http://www.domain.tld/subfolder/sites/default/files/css/css_xaJU72jAuGdwaW-AT8DAVp4DqDeKRUXAJArM-ju9zyk.css" media="all" />
<link rel="stylesheet" href="http://www.domain.tld/subfolder/sites/default/files/css/css_twK2o_TguRokHm556wgfgJQcNKDGnohz7jRgALpSMgo.css" media="all" />
<link rel="stylesheet" href="http://www.domain.tld/subfolder/sites/default/files/css/css_e28YCM1EJwVNlVrH2rzSh2pyE8l1LKY9lxXqWeSY7S0.css" media="all" />

How can I change this to the way Drupal generates it:

<link rel="stylesheet" href="/subfolder/sites/default/files/css/css_YInDv_rTqgPALb4zztYVH-_aoZ21p7QQhGSv6L8GybI.css" media="all" />

The reasoning is that the site runs behind a caching proxy and the base url can be diffrent.  I know I can set a $base_url in settings.php, but that's not an ideal solution for a few reaons.


I'm a little uncertain of exactly what you are trying to do. Have you seen this page: https://api.backdropcms.org/themes

Are you trying to load assets without putting them in your theme directory. Because if you do, then I think you would just list the relative paths to your CSS and JS assets in the theme.info file. 

Backdrop seems to load them using the full URL including the domain and protocol.

I don't think this is true. I mean Backdrop will convert the paths to full URL's for the browser. But, I can't think of anywhere that Backdrop asks for hard-coded paths for assets within the site. 

indigoxela's picture

How can I change this to the way Drupal generates it

To be more precise: the way Drupal 6 did it... ;-)

Drupal 7 also uses full urls.

The reasoning is that the site runs behind a caching proxy

The proxy should be able to handle that correctly. You'll need to set up things in your settings.php, see the comments in that file in section "Reverse Proxy Configuration" for instructions.

I think I may have caused some confusion with the way I incorrectly used the terms "absolute" and "relative" URL's.

I was able work around immediate problem by putting this as my base URL:

$base_url = '//www.domain.tld/subfolder'; // NO trailing slash!

That resulted in URL being written as:

<meta charset="utf-8" />
<link rel="shortcut icon" href="//www.domain.tld/subfolder/themes/sometheme/favicon.ico" type="image/vnd.microsoft.icon" />

<link rel="stylesheet" href="//www.domain.tld/subfolder/sites/default/files/css/css_YInDv_rTqgPALb4zztYVH-_aoZ21p7QQhGSv6L8GybI.css" media="all" />
<link rel="stylesheet" href="//www.domain.tld/subfolder/sites/default/files/css/css_xaJU72jAuGdwaW-AT8DAVp4DqDeKRUXAJArM-ju9zyk.css" media="all" />
<link rel="stylesheet" href="//www.domain.tld/subfolder/sites/default/files/css/css_twK2o_TguRokHm556wgfgJQcNKDGnohz7jRgALpSMgo.css" media="all" />
<link rel="stylesheet" href="//www.domain.tld/subfolder/sites/default/files/css/css_e28YCM1EJwVNlVrH2rzSh2pyE8l1LKY9lxXqWeSY7S0.css" media="all" />

It's still an 'absolute' URL by definition, but in this specific case the desire was to load the assets using the current protocol.

Ideally it should be referring to the assets using 'relative' URLs (ie. without the hostname part).

The D6 behavior was very convenient as I didn't have to worry about hard coded host names and paths.


I just tried using only the subfolder as the $base_url and that got me much closer to the desired behavior.

$base_url = '/subfolder'; // NO trailing slash!