I don't like the idea of having all my images referenced with the code "/sites//files/images/xyz.jpg" - I would rather reference them with "/images/xyz.jpg". This is for two reasons - (1) it's nicer and (2) it promotes flexibility in the future regarding my site domain and the location of the files directory within drupal.

So, I created a sybolic link: /images -> /sites//files/images. Now I can reference all my images with /images/xyz.jpg.

Unfortunately IMCE doesn't support this - I noticed by looking at the code that file_directory_path() is a hard-coded prefix to whatever directory path you specify at the moment.

Would it be possible to support a totally custom path - with no file_directory_path() prefix? Or can you give me some solid reasons as to why my logic above is wrong?



fletchgqc’s picture

Sorry some things got cut out of the above post... I always do that with angle brackets! The references to /sites//files/images/xyz.jpg should be /sites/<mydomain>/files/images/xyz.jpg

ufku’s picture

Any symbolic link under file_directory_path must be resolved concerning security issues. However you can have a file_directory_path which is a symbolic link. In your case, creating a symbolic link 'files' to 'sites/your.domain/files' and changing file_directory_path to 'files'(which you miss) should work.
Note that image paths become 'files/images' not just 'images'.

fletchgqc’s picture

That's an interesting idea. It more or less solves my problems. It's not as "nice" as having simply "/images" but it's hard to argue with...

fletchgqc’s picture

Status: Active » Closed (fixed)

For interest of searchers, this is what I settled for in the end and it worked well.

tinsmon’s picture

I'm just getting towards the end of migrating our departments' website from (mostly) static html to a Drupal site on a couple of Apache servers (currently on the dev server, soon moving to prod) in a multi-site config. This server is maintained by our central IT dept. here on campus, so I don't have any command line access or any say in the overall Drupal server configuration (I do have FTP access to our site's file system including files and modules). The file system is setup using the typical multi-site config. outlined here:


I've run into the exact /files path issue here and solved the first part of the problem in a similar way, using the .htaccess solution outlined in the link above. So, I'm halfway there just as fletchgqc was when he started this thread. I've got my site setup so that even though the "correct" path to my files folder is http://my site name/sites/my site name/files using the path http://my site name/files works just fine. Except that IMCE still returns the longer version of the path to the code when inserting images or linking to documents.

I believe what I need to do is exactly this (from ufku's post above):

"In your case,....and changing file_directory_path to 'files'(which you miss) should work."

The problem is that I do not know how to do this. I've searched Drupal.org extensively and can't seem to find the insructions. Can someone please post the procedure to change IMCE's default path from /sites/my site name/files to just /files?

It would be a great help to me as it would save a lot of work when we have to move from the dev server to the prod server and the site name changes.

As this is my first post I'm not sure of the etiquette on re-opening a closed issue but this seemed like the most logical place to ask this question.



tinsmon’s picture

Title: Support symbolic linking to files directory » Support symbolic linking to files directory - How to change IMCE's file path setting?
Status: Closed (fixed) » Active
ufku’s picture

Title: Support symbolic linking to files directory - How to change IMCE's file path setting? » Support symbolic linking to files directory

It's the "file system path" at "admin/settings/file-system"

tinsmon’s picture

Thanks, ufku.

Unfortunately, it didn't work out the way I'd planned. The File System doesn't allow "/files" and when I just put "files" in it doesn't put me in the right place when I open the file browser via IMCE. In fact, I can't tell what directory it's allowing me to browse, but there are no files there.

I can only assume the .htaccess settings that fix the issue when browsing the site via the web don't apply to an internal, Drupal function like the File System Path. I've put in a request to our server admin. to setup the symlink in Apache as fletchgqc did above. I'm hoping that fixes the issue once and for all. I'll report back.

tinsmon’s picture

Status: Active » Closed (fixed)

Using a symlink did the trick.

Just a little more background for the benefit of any other new Drupal users that might happen upon this thread. As I'm not a Unix guy it took me a while to understand the difference between an alias and a symlink, but I do get it now. Since IMCE seems to be browsing the actual server file system (as opposed to browsing via the web) the alias or .htaccess redirects of the files folder do not apply. It is only in using a symlink at the root of the multi-site drupal install that you can actually re-direct the File System Path and, thus, IMCE.

This seems like an awful lot of hoops to jump through to fix what is, essentially, a flaw in the standard multi-site Drupal install procedure (not really an IMCE issue) http://drupal.org/node/53705. By including the site name in the files path it turns a relative link into a kind of pseudo-absolute link.

For all practical purposes these two paths are the same:

since they would both have to be changed in your code if you move your site from one server to another (as in a dev/prod setup). This really defeats the whole point of relative links.

Oh well, I'm all set now.

Thanks to ufku and fletchgqc

Benj’s picture

I'm confused. Are we choosing to live with IMCE using these paths?

Anonymous’s picture

Good lord, how many people have to cry out for relative URLs to become truly relative before it actually happens?

stockliasteroid’s picture

Status: Closed (fixed) » Active

Re-opening... Though it is an edge case, this is an issue with Aegir as well. We're considering moving to Aegir as a hosting solution, and Aegir doesn't rewrite URLs in $node->body or $node->teaser when you clone a site to a new URL. It does update the URLs in the files table, but that doesn't help us when images are inserted using IMCE, as the path to the image is stored in the node body in the image tag.

Aegir's solution is to perform the first "half" of the solution, as outlined by tinsmon above. (see http://community.aegirproject.org/node/43, the section labeled "Files rewrite rule") However, we still need a way to rewrite the URLs that IMCE adds to the node body. We can't change the files dir path or use a symlink, as those don't work in a multisite configuration, which is what Aegir is. The .htaccess rewrite obviously only concerns HTTP requests for those images and won't handle IMCE directly browsing the file system for images. So... we need a way to leave the files dir as is, not use a symlink, but instead to alter the URLs that IMCE uses. So instead of the full path to the files dir, we could just use /files, which the aegir htaccess mod would ensure always redirects onto the correct files dir based on the multisite setup.

Thoughts? I haven't cracked open IMCE to look yet... Perhaps it might never make it into core IMCE since it's edge, but it would still be a good problem to solve for those who maintain a patches folder for their site...

ufku’s picture

Status: Active » Closed (fixed)

This issue is not specific to Aegir or IMCE. It's the common case when you move your site from http://example.com/subdir to http://example.com. Any hard-coded relative path in body fields would be broken. The only solution is to replace src="/subdir and href="/subdir with src="/ and href="/ in body and teaser fields using SQL.

Using a sub-domain for development site prevents such cases. Moving from http://sub.example.com to http://example.com would not break any relative paths in body fields.

The issue is all about embedding static links and paths inside static content and IMCE can not do anything about it.

stockliasteroid’s picture

Issue tags: +aegir

I agree that it's not IMCE's "fault", I'm just looking for a non-invasive way to deal with it. Using a sub-domain is irrelevant in the Aegir case, however, because Aegir is based around Drupal multi-site, which uses the hostname in the file system. So, if you change the hostname of a site via an Aegir clone, the path to the files directory changes: sites/sub.example.com/files becomes sites/example.com/files. If you have a large number of sites in Aegir, there could be hundreds of directories in sites/*, one for each site, each containing it's own files dir for that site.

The Aegir solution is to reference your files directory as /files in any relative links, using mod_rewrite to rewrite the URL to the correct sites/hostname/files directory based on the request's host. If it's done this way, it wouldn't matter that your site is a multi-site install that changes from sub.example.com to example.com and that your files directory has changed as a result, all of your files paths point to /files, and nothing need change in your node bodies.

The reason I'm working on this is because IMCE is the only module in our stack that inserts relative paths to the files directory into the node bodies. Everything else uses the files table, which Aegir handles. Obviously this is by design for IMCE, so all I want to find is a way to get IMCE to use "/files" as the path it uses for images instead of "/sites/hostname/files", which is what Drupal will consider to be the file directory.

I don't expect this to be a change that should be made in IMCE, as it's a very special case. However, some direction about the best place to "hook" into IMCE (javascript function override, etc) so that I don't have to patch IMCE directly, would be great. My goal is to create a module that can cooperate with IMCE to solve the Aegir situation, so that WYSIWYG remains a viable option in Aegir-deployed sites.


ufku’s picture

You may try overriding base URL of files directory using javascript

if (window.imce) {
  // Runs when imce loads
  imce.hooks.load.push(function() {
    // Override base file URL. This was probably something like '/sites/domain/files/'
    imce.conf.furl = '/files/';
    // Or you can override imce.getURL() method that generates file URLs

This script can be included in theme's script.js or imce-page.tpl.php or imce-content.tpl.php or via drupal_add_js(make sure the type is 'theme' if you add it as a file).

stockliasteroid’s picture


Thanks very much for the response! I was looking at the same option (actually I was looking at overriding getURL(), but this looks cleaner), but I really wanted your confirmation that it was a good idea :).

I'll give that a shot! Thanks!