diff --git a/index.php b/index.php
index b4cac1879c6797f177e00dc6cad769f90f73b268..1858865875b69078b50a6da4c9a905729489bee3 100644
--- a/index.php
+++ b/index.php
@@ -57,7 +57,7 @@ elseif(OC_User::isLoggedIn()) {
 		exit();
 	}
 	else {
-		OC_Util::redirectToDefaultPage();
+		OC::loadapp();
 	}
 }
 
diff --git a/lib/base.php b/lib/base.php
index f3dacdc0f76ae7769891d5447eab1519ae9d9cbd..c21ab9735935556824dace30f9aeaa75a14ecb50 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -62,15 +62,22 @@ class OC{
 	 * the root path of the 3rdparty folder for http requests (e.g. owncloud/3rdparty)
 	 */
 	public static $THIRDPARTYWEBROOT = '';
-        /**
-         * The installation path of the apps folder on the server (e.g. /srv/http/owncloud)
-         */
-        public static $APPSROOT = '';
-        /**
-         * the root path of the apps folder for http requests (e.g. owncloud)
-         */
-        public static $APPSWEBROOT = '';
-
+	/**
+	 * The installation path of the apps folder on the server (e.g. /srv/http/owncloud)
+	 */
+	public static $APPSROOT = '';
+	/**
+	 * the root path of the apps folder for http requests (e.g. owncloud)
+	 */
+	public static $APPSWEBROOT = '';
+	/*
+	 * requested app
+	 */
+	public static $REQUESTEDAPP = '';
+	/*
+	 * requested file of app
+	 */
+	public static $REQUESTEDFILE = '';
 	/**
 	 * SPL autoload
 	 */
@@ -161,12 +168,15 @@ class OC{
 		}
 
 		// search the apps folder
-		if(file_exists(OC::$SERVERROOT.'/apps')){
+		if(OC_Config::getValue('appsroot', '')<>''){
+			OC::$APPSROOT=OC_Config::getValue('appsroot', '');
+			OC::$APPSWEBROOT=OC_Config::getValue('appsurl', '');
+		}elseif(file_exists(OC::$SERVERROOT.'/apps')){
 			OC::$APPSROOT=OC::$SERVERROOT;
 			OC::$APPSWEBROOT=OC::$WEBROOT;
 		}elseif(file_exists(OC::$SERVERROOT.'/../apps')){
-			OC::$APPSWEBROOT=rtrim(dirname(OC::$WEBROOT), '/');
 			OC::$APPSROOT=rtrim(dirname(OC::$SERVERROOT), '/');
+			OC::$APPSWEBROOT=rtrim(dirname(OC::$WEBROOT), '/');
 		}else{
 			echo("apps directory not found! Please put the ownCloud apps folder in the ownCloud folder or the folder above. You can also configure the location in the config.php file.");
 			exit;
@@ -261,6 +271,13 @@ class OC{
 		ini_set('session.cookie_httponly','1;');
 		session_start();
 	}
+	
+	public static function loadapp(){
+		if(file_exists(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP)){
+			OC_App::loadApps();
+			require_once(OC::$APPSROOT . '/apps/' . OC::$REQUESTEDAPP . '/index.php');
+		}
+	}
 
 	public static function init(){
 		// register autoloader
@@ -371,6 +388,9 @@ class OC{
 
 		//make sure temporary files are cleaned up
 		register_shutdown_function(array('OC_Helper','cleanTmp'));
+		
+		self::$REQUESTEDAPP = (isset($_GET['app'])?strip_tags($_GET['app']):'files');
+		self::$REQUESTEDFILE = (isset($_GET['file'])?(OC_Helper::issubdirectory(OC::$APPSROOT . '/' . self::$REQUESTEDAPP . '/' . $_GET['file'], OC::$APPSROOT . '/' . self::$REQUESTEDAPP)?$_GET['file']:null):null);
 	}
 }
 
@@ -399,4 +419,4 @@ if(!function_exists('get_temp_dir')) {
 	}
 }
 
-OC::init();
+OC::init();
\ No newline at end of file
diff --git a/lib/helper.php b/lib/helper.php
index 412f0e6b7643377493c8cf5209d9eaba0b4fb9f8..52278f5c3a23563fc1d98a932fcb48801640190e 100755
--- a/lib/helper.php
+++ b/lib/helper.php
@@ -520,4 +520,15 @@ class OC_Helper {
 
         return $newname;
     }
+	
+	/*
+	 * checks if $sub is a subdirectory of $parent
+	 * 
+	 * @param $sub 
+	 * @param $parent
+	 * @return bool
+	 */
+	public static function issubdirectory($sub, $parent){
+		return (substr(realpath($sub), 0, strlen(realpath($parent))) == realpath($parent))?true:false;
+	}
 }
diff --git a/lib/util.php b/lib/util.php
index 2ea392ec31dc896c065ce4a7f5bee4d9e7ffa404..e3c20ddb8587ba524d4697a5b480f0ecc94254f2 100644
--- a/lib/util.php
+++ b/lib/util.php
@@ -292,7 +292,7 @@ class OC_Util {
 		if(isset($_REQUEST['redirect_url'])) {
 			header( 'Location: '.$_REQUEST['redirect_url']);
 		} else {
-			header( 'Location: '.OC::$WEBROOT.'/'.OC_Appconfig::getValue('core', 'defaultpage', 'files/index.php'));
+			header( 'Location: '.OC::$WEBROOT.'/'.OC_Appconfig::getValue('core', 'defaultpage', '?app=files'));
 		}
 		exit();
 	}