diff --git a/include/class.osticket.php b/include/class.osticket.php
index dce94a8feefde5518ca06b85d0a841bfe7304502..f27efe4a9323487b74af412582609126a94f8a21 100644
--- a/include/class.osticket.php
+++ b/include/class.osticket.php
@@ -397,7 +397,10 @@ class osTicket {
         $file = str_replace('\\','/', $frame['file']);
         $path = substr($file, strlen(ROOT_DIR));
         if($path && ($pos=strpos($_SERVER['SCRIPT_NAME'], $path))!==false)
-            return substr($_SERVER['SCRIPT_NAME'], 0, $pos);
+            return ($pos) ? substr($_SERVER['SCRIPT_NAME'], 0, $pos) : '/';
+
+        if (self::is_cli())
+            return '/';
 
         return null;
     }