How to change the directory of file_create_url to default for a custom domain Suppose, we have a file: /sites/default/files/picture.jpg

Drupal is installed into a subdirectory: /drupal. There are 2 domains, attached to the site:


exchange
exchange-test (uses different DB)




 | domain        | settings.php path     |
 |---------------+-----------------------+
 | exchange      | /sites/default/       |
 | exchange-test | /sites/exchange-test/ |


When we call 

print file_create_url('public://picture.jpg');


we get:

| site          | result                                        |
|---------------+-----------------------------------------------|
| exchange      | /drupal/sites/default/files/picture.jpg       |
| exchange-test | /drupal/sites/exchange-test/files/picture.jpg |


But the file is stored in default directory even for exchange-test domain.

As far as I could find, the path is being generated, using function conf_path. It scans the config directory to find a subdir with current domain name:

 $server = explode('.', implode('.', array_reverse(explode(':', rtrim($_SERVER['HTTP_HOST'], '.')))));
  for ($i = count($uri) - 1; $i &gt; 0; $i--) {
    for ($j = count($server); $j &gt; 0; $j--) {
      $dir = implode('.', array_slice($server, -$j)) . 
             implode('.', array_slice($uri, 0, $i));
      if (isset($sites[$dir]) &amp;&amp; 
          file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $sites[$dir])) {
            $dir = $sites[$dir];
      }
      if (file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $dir . '/settings.php') || 
         (!$require_settings &amp;&amp; file_exists(DRUPAL_ROOT . '/' . $confdir . '/' . $dir))) {
            $conf = "$confdir/$dir";
            return $conf;
      }
    }
  }


If found, it uses this directory as files path.

So, one way is to temporarily change $_SERVER['HTTP_HOST']:

$_SERVER['HTTP_HOST'] = 'exchange';
print file_create_url('public://picture.jpg');
$_SERVER['HTTP_HOST'] = 'exchange-test';


Will give the correct result. But this trick seems clumsy to me. Is there any way to get the default directory without such hacks?
try setting the public file system path in your -test site to match that of the other in /admin/config/media/file-system