Score:0

Why are the images referenced using a relative path instead of an absolute path?

zw flag

I have installed my Drupal site on my localhost under a path like /websites/mysite/drupal. Most files get loaded correctly, such as those at /websites/mysite/drupal/sites/default/files.

For some reasons, if I have images in a module or theme folder, such as /websites/mysite/drupal/module/custom/mymodule or /websites/name/drupal/themes/custom/mytheme, they do not get loaded. In this circumstance, Drupal is trying to load the image file from module/custom/mymodule instead of /websites/mysite/drupal/module/custom/mymodule.

The strange thing is that CSS files and JS files, along with themes and modules themselves, get loaded correctly. It is just the images files, which are being loaded without the base URL.

I was able to set Public file base URL, in the settings.php file which allows the files at sites/default/files to be loaded correctly. This does not work on files in themes and modules though.

So how can I set my Drupal site to load images from /websites/mysite/drupal/module/custom/mymodule instead of module/custom/mymodule?

leymannx avatar
ne flag
Uncomment that line: https://git.drupalcode.org/project/drupal/-/blob/9.3.0/.htaccess#L112 and then write `RewriteBase /websites/mysite/drupal`
May  avatar
zw flag
thanks @leymannx, this has not resolved the problem though
4uk4 avatar
cn flag
You can move Drupal 8/9 into sub directories without changing anything in settings.php or .httaccess. I've done this many times without problems. This is more likely an issue with how the images are rendered. See https://drupal.stackexchange.com/questions/296614/get-base-url-in-a-custom-block/ and https://drupal.stackexchange.com/questions/230077/how-to-force-image-urls-as-https
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.