diff --git a/core/js/js.js b/core/js/js.js
index d9b3b54e0a1628104a0396d22d261f0e261d38ab..5442039c2949a9480ff3cd78ded3b50b58046412 100644
--- a/core/js/js.js
+++ b/core/js/js.js
@@ -12,7 +12,14 @@ var oc_current_user = document.getElementsByTagName('head')[0].getAttribute('dat
 var oc_requesttoken = document.getElementsByTagName('head')[0].getAttribute('data-requesttoken');
 
 if (typeof oc_webroot === "undefined") {
-	oc_webroot = location.pathname.substr(0, location.pathname.lastIndexOf('/'));
+	oc_webroot = location.pathname;
+	var pos = oc_webroot.indexOf('/index.php/');
+	if (pos !== -1) {
+		oc_webroot = oc_webroot.substr(0, pos);
+	}
+	else {
+		oc_webroot = oc_webroot.substr(0, oc_webroot.lastIndexOf('/'));
+	}
 }
 if (oc_debug !== true || typeof console === "undefined" || typeof console.log === "undefined") {
 	if (!window.console) {
diff --git a/lib/base.php b/lib/base.php
index baf73b2fb9f3b0941c5b42422fc5d958a7a79278..a6033f03f8cc35d43a74936d9a72683b27a780a3 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -265,6 +265,7 @@ class OC {
 					$minimizerCSS->clearCache();
 					$minimizerJS = new OC_Minimizer_JS();
 					$minimizerJS->clearCache();
+					OC_Util::addScript('config'); // needed for web root
 					OC_Util::addScript('update');
 					$tmpl = new OC_Template('', 'update.admin', 'guest');
 					$tmpl->assign('version', OC_Util::getVersionString());