diff --git a/core/templates/layout.guest.php b/core/templates/layout.guest.php
index 2bd2e20df70852ee02fc0f563c77df894eaebbda..7ba7abdbf12238bc404a375eeb2ee8996a974fc2 100644
--- a/core/templates/layout.guest.php
+++ b/core/templates/layout.guest.php
@@ -9,6 +9,7 @@
 		<?php endforeach; ?>
 		<script type="text/javascript">
 			var oc_webroot = '<?php echo OC::$WEBROOT; ?>';
+			var oc_appswebroot = '<?php echo OC::$APPSWEBROOT; ?>';
 		</script>
 		<?php foreach($_['jsfiles'] as $jsfile): ?>
 			<script type="text/javascript" src="<?php echo $jsfile; ?>"></script>
diff --git a/lib/template.php b/lib/template.php
index eccf011e8d2917e8789c2f5c4fc33cbd245c7a58..57e9c15f5e689a6c79ae0a6ed53f71e38ab6259a 100644
--- a/lib/template.php
+++ b/lib/template.php
@@ -323,11 +323,11 @@ class OC_Template{
 	 */
         public function appendIfExist($type, $root, $web, $file) {
                 if (is_file($root.'/'.$file)) {
-                		if($type == 'cssfiles' && $root == OC::$APPSROOT){
-                				$pathes = explode('/', $file);
-                				$app = $pathes['1'];
-                				unset($pathes['0']);
-                				unset($pathes['1']);
+                		$pathes = explode('/', $file);
+                		if($type == 'cssfiles' && $root == OC::$APPSROOT && $pathes[0] == 'apps'){
+                				$app = $pathes[1];
+                				unset($pathes[0]);
+                				unset($pathes[1]);
                 				$path = implode('/', $pathes);
                 				$this->append( $type, OC_Helper::linkTo($app, $path));
                 		}else{