diff --git a/stage_file_proxy.module b/stage_file_proxy.module
index 7b528f6..4ca24a9 100644
--- a/stage_file_proxy.module
+++ b/stage_file_proxy.module
@@ -32,7 +32,7 @@ function stage_file_proxy_init() {
     }
 
     if (variable_get('stage_file_proxy_hotlink', FALSE)) {
-      header("Location: $server/$remote_file_dir/$relative_path");
+      header("Location: " . $server . ($remote_file_dir != '' ? '/' . $remote_file_dir : '' ) . '/' . $relative_path);
       exit;
     }
     elseif (_stage_file_proxy_fetch($server, $remote_file_dir, $relative_path)) {
@@ -58,12 +58,12 @@ function _stage_file_proxy_fetch($server, $remote_file_dir, $relative_path) {
   foreach ($dirs as $dir) {
     $tree[] = $dir;
     $dir_path = $file_dir . '/' . implode('/', $tree);
-    $remote_dir_path = $remote_file_dir . '/' . implode('/', $tree);
+    $remote_dir_path = ($remote_file_dir != '' ? $remote_file_dir . '/' : '') . implode('/', $tree);
     if (!is_dir($dir_path)) {
       mkdir($dir_path);
     }
   }
-  $url = $server . '/' . $remote_dir_path . '/' . rawurlencode($filename);
+  $url = $server . '/' . ($remote_dir_path != '' ? $remote_dir_path . '/' : '') . rawurlencode($filename);
   $ch = curl_init($url);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
