diff --git a/include/class.osticket.php b/include/class.osticket.php
index f23dc824c68c541fd2799259cd4c5acdc954f794..d481ee60c7e694f40e8b0369c6544873b8e1c876 100644
--- a/include/class.osticket.php
+++ b/include/class.osticket.php
@@ -367,63 +367,27 @@ class osTicket {
                 || !strcasecmp($_SERVER['DOCUMENT_ROOT'], $dir))
             return '/';
 
-        /* If DOCUMENT_ROOT is set and isn't the same as the directory for
-         * main.inc.php, then assume that the two have something in common.
-         * For instance, you might have the following configurations
-         *
-         * +-----------------+-----------------------+------------+----------+
-         * | DOCUMENT_ROOT   | dirname(main.inc.php) | ROOT_PATH  | Comments |
-         * +-----------------+-----------------------+------------+----------+
-         * | /var/www        | /var/www/osticket     | /osticket/ | vanilla  |
-         * | /srv/httpd/www  | /httpd/www            | /          | chrooted |
-         * | /srv/httpd/www  | /httpd/www/osticket   | /osticket/ | chrooted |
-         * +-----------------+-----------------------+------------+----------+
-         *
-         * This algorithm will walk the two paths right to left, chipping
-         * away at the path of main.inc.php. When the two paths are equal,
-         * the part removed from the main.inc.php path is the ROOT_PATH
-         */
-        $dir = str_replace('\\', '/', $dir);
-        $root = str_replace('\\', '/', $_SERVER['DOCUMENT_ROOT']);
-
-        // Not chrooted
-        if(strpos($dir, $root)!==false)
-            return substr($dir, strlen($root));
-
-        // Chrooted ?
-        $path = '';
-        while (strpos($root, $dir) === false) {
-            $lastslash = strrpos($dir, '/');
-            $path = substr($dir, $lastslash) . $path;
-            $dir = substr($dir, 0, $lastslash);
-            if (!$dir)
-                break;
-        }
-
-        if($dir && $path)
-            return $path;
-
-        /* The last resort is to try and use SCRIPT_FILENAME and
-         * SCRIPT_NAME. The SCRIPT_FILENAME server variable should be the
-         * full path of the originally-executed-script. The SCRIPT_NAME
-         * should be the path of that script inside the DOCUMENT_ROOT. This
-         * is most likely useful if osTicket is run using something like
-         * Apache UserDir setting where the DOCUMENT_ROOT of Apache and the
-         * installation path of osTicket have nothing in comon.
+        /* The main idea is to try and use full-path filename of PHP_SELF and
+         * SCRIPT_NAME. The SCRIPT_NAME should be the path of that script
+         * inside the DOCUMENT_ROOT. This is most likely useful if osTicket
+         * is run using something like Apache UserDir setting where the
+         * DOCUMENT_ROOT of Apache and the installation path of osTicket
+         * have nothing in comon.
          *
          * +---------------------------+-------------------+----------------+
-         * | SCRIPT_FILENAME           | SCRIPT_NAME       | ROOT_PATH      |
+         * | PHP Script                | SCRIPT_NAME       | ROOT_PATH      |
          * +---------------------------+-------------------+----------------+
          * | /home/u1/www/osticket/... | /~u1/osticket/... | /~u1/osticket/ |
          * +---------------------------+-------------------+----------------+
          *
          * The algorithm will remove the directory of main.inc.php from
-         * SCRIPT_FILENAME. What's left should be the script executed inside
+         * as seen. What's left should be the script executed inside
          * the osTicket installation. That is removed from SCRIPT_NAME.
          * What's left is the ROOT_PATH.
          */
-        $path = substr($_SERVER['SCRIPT_FILENAME'], strlen(ROOT_DIR));
-        if($path  && ($pos=strpos($_SERVER['SCRIPT_NAME'], $path))!==false)
+        $frame = array_pop(debug_backtrace(false));
+        $path = substr($frame['file'], strlen(ROOT_DIR));
+        if($path && ($pos=strpos($_SERVER['SCRIPT_NAME'], $path))!==false)
             return substr($_SERVER['SCRIPT_NAME'], 0, $pos);
 
         return null;