So normally I can do <img src="<?php base_url(); ?>/default/files/image.png" /> and that works just fine if I enable the php filter.

The trouble is that enabling the php filter disables all shortcodes. My drupal site is not installed in the root of the domain so <img src="/default/files" /> will not work.

Is it possible to have a relative path (this site will be moving once I'm finished) but have drupal know it's relative to the base url without using php? Maybe a setting?

  • What Drupal version? Please tag your question with a Drupal version.
    – leymannx
    Commented Jan 13, 2017 at 16:10

2 Answers 2


in your .htaccess file, you could try something like:

RewriteEngine on

(in case it is not already turned on)

RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^$ subfolder [L]

(where in this case 'subfolder' represents the address of the installation)

This should create a system based, base url, rather than a php based url - so relative paths should work.


You can use the pathologic module. One of its uses cases is related to subfolders:

The address of your site has changed. Perhaps you moved to a shiny new domain name, or perhaps you moved the Drupal installation from one subdirectory to another. Now all the images and internal links in your content don’t work. Using Pathologic is an alternative to going through all of the site’s content and correcting the paths manually.



You can configure it in:


As an example if your website is on /staging/ (dev.example.org domain)

You should include http://dev.example.org/staging/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.