When developing websites for clients, each developer has all sites under a relative path in his htdocs dir:

  • /client1site/
  • /client2site/
  • /clientsite/ and so on

Most links within the drupal installation, in content or image srcs have to be absolute to this path: /client1site/en/a-nice-article/ in order to work.

But when client 1's site goes to production, links stop to work because now the structure looks like www.client1site.com/en/a-nice-article.

The situation is general, in the sense that you can develop under a path /X/ and have to go to production under a path /Y/.

Can this be solved with an easy way without having to edit all content or image srcs by hand? Can some mod_rewrite wizardry save the day?

3 Answers 3


Frankly, I have never suffered from any path reference issue that you are describing, speaking of managed files. As per unmanaged files, which laying around on the ftp server, that you may happen to refer to in raw code or WYSIWYG editors, make sure you don't use absolute paths starting with domain name. Check your WYSIWYG editor settings. Instead, you'd want to:

  • use links starting with slash - I call them root links
  • edit the settings.php file and provide an explicit URL of your current site root in the $base_url variable. This is what the root links will refer to as base. Thus, when you move your site to another domain, it should require just changing of that one value.

I'm not sure there is a tool to do global replacements of absolute path you might already have. You could however dig into database and do a global search on it.

  • I'm flagging this as an answer since it is in the spirit of my question--I need a installation/configuration solution, not a something dynamic. Commented May 28, 2012 at 12:07

There is a module that can help with this situation. The Pathologic module is (from the module's page)

an input filter which can correct paths in links and images in your Drupal content in situations which would otherwise cause them to “break;” for example, if the URL of the site changes, or the content was moved to a different server. Pathologic can also solve the problem of missing images and broken links in your site’s RSS feeds.

Basically, once you set it up (slightly more difficult than the average module but documented well) it works silently in the background and keeps your links working properly. Warning: as noted on the project page, it has some issues with multilingual sites.


WYSIWYG editors usually do so by hard coding the absolute urls when images are inserted using them. This can be overcome by pathlogic module as Patrick Kenny suggested, that works as input filter to change the domain in content with the current on which the Drupal instance is configured.

But always make sure

  • to use relative paths
  • to generate URLs by url() or l() function even if to generate absolute paths (see documentation)
  • to append $base_path or base_path(). By default it is '/' but when Drupal is configured in some sub directory it will reflect the change e.g. /subdir/
  • Good point. It's also worth mentioning that with Pathologic installed, in text format configuration screen, you can find a text field labeled "All base paths for this site:" where you can provide all base path alternatives. Commented May 25, 2012 at 19:41

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.