diff --git a/apps/calendar/index.php b/apps/calendar/index.php
index 4b87119592734d8e8a69bf2f38d9ca7a9404a462..cbfe0027b7be1c4aca996ab13855df3c1ed8f61c 100644
--- a/apps/calendar/index.php
+++ b/apps/calendar/index.php
@@ -24,8 +24,17 @@ foreach($calendars as $calendar){
 	}
 }
 
-$eventSources[] = array('url' => '?app=calendar&getfile=ajax/events.php?calendar_id=shared_rw', 'backgroundColor' => '#1D2D44', 'borderColor' => '#888', 'textColor' => 'white', 'editable'=>'true');
-$eventSources[] = array('url' => '?app=calendar&getfile=ajax/events.php?calendar_id=shared_r', 'backgroundColor' => '#1D2D44', 'borderColor' => '#888', 'textColor' => 'white', 'editable' => 'false');
+$events_baseURL = OCP\Util::linkTo('calendar', 'ajax/events.php');
+$eventSources[] = array('url' => $events_baseURL.'?calendar_id=shared_rw',
+		'backgroundColor' => '#1D2D44',
+		'borderColor' => '#888',
+		'textColor' => 'white',
+		'editable'=>'true');
+$eventSources[] = array('url' => $events_baseURL.'?calendar_id=shared_r',
+		'backgroundColor' => '#1D2D44',
+		'borderColor' => '#888',
+		'textColor' => 'white',
+		'editable' => 'false');
 
 OCP\Util::emitHook('OC_Calendar', 'getSources', array('sources' => &$eventSources));
 $categories = OC_Calendar_App::getCategoryOptions();
diff --git a/apps/calendar/templates/part.choosecalendar.rowfields.php b/apps/calendar/templates/part.choosecalendar.rowfields.php
index 4492ce731c974295749fb7e3d09046088bb9d4ef..d29113c9a615e45097ba53a11df253866d9d8fa3 100644
--- a/apps/calendar/templates/part.choosecalendar.rowfields.php
+++ b/apps/calendar/templates/part.choosecalendar.rowfields.php
@@ -11,7 +11,7 @@
   <a href="#" onclick="Calendar.UI.showCalDAVUrl('<?php echo OCP\USER::getUser() ?>', '<?php echo rawurlencode(html_entity_decode($_['calendar']['uri'], ENT_QUOTES, 'UTF-8')) ?>');" title="<?php echo $l->t('CalDav Link') ?>" class="action"><img class="svg action" src="<?php echo OCP\Util::imagePath('core', 'actions/public.svg') ?>"></a>
 </td>
 <td width="20px">
-  <a href="?app=calendar&amp;getfile=export.php?calid=<?php echo $_['calendar']['id'] ?>" title="<?php echo $l->t('Download') ?>" class="action"><img class="svg action" src="<?php echo OCP\Util::imagePath('core', 'actions/download.svg') ?>"></a>
+  <a href="<?php echo OCP\Util::linkTo('calendar', 'export.php') . '?calid=' . $_['calendar']['id'] ?>" title="<?php echo $l->t('Download') ?>" class="action"><img class="svg action" src="<?php echo OCP\Util::imagePath('core', 'actions/download.svg') ?>"></a>
 </td>
 <td width="20px">
   <a href="#" onclick="Calendar.UI.Calendar.edit(this, <?php echo $_['calendar']['id'] ?>);" title="<?php echo $l->t('Edit') ?>" class="action"><img class="svg action" src="<?php echo OCP\Util::imagePath('core', 'actions/rename.svg') ?>"></a>
diff --git a/apps/calendar/templates/part.editevent.php b/apps/calendar/templates/part.editevent.php
index 102366f8f08f67fe4204d084260461dea18155bc..ea91192cc66150a435ec3c484a6d80c21691ed60 100644
--- a/apps/calendar/templates/part.editevent.php
+++ b/apps/calendar/templates/part.editevent.php
@@ -5,9 +5,9 @@
 <?php echo $this->inc("part.eventform"); ?>
 	<div style="width: 100%;text-align: center;color: #FF1D1D;" id="errorbox"></div>
 	<span id="actions">
-		<input type="button" class="submit" style="float: left;" value="<?php echo $l->t("Submit");?>" onclick="Calendar.UI.validateEventForm('?app=calendar&getfile=ajax/event/edit.php');">
-		<input type="button" class="submit" style="float: left;" name="delete" value="<?php echo $l->t("Delete");?>" onclick="Calendar.UI.submitDeleteEventForm('?app=calendar&getfile=ajax/event/delete.php');">
-		<input type="button" class="submit" style="float: right;" name="export" value="<?php echo $l->t("Export");?>" onclick="window.location='?app=calendar&getfile=export.php?eventid=<?php echo $_['eventid'] ?>';">
+		<input type="button" class="submit" style="float: left;" value="<?php echo $l->t("Submit");?>" onclick="Calendar.UI.validateEventForm('<?php echo OCP\Util::linkTo('calendar', 'ajax/event/edit.php') ?>');">
+		<input type="button" class="submit" style="float: left;" name="delete" value="<?php echo $l->t("Delete");?>" onclick="Calendar.UI.submitDeleteEventForm('<?php echo OCP\Util::linkTo('calendar', 'ajax/event/delete.php') ?>');">
+		<input type="button" class="submit" style="float: right;" name="export" value="<?php echo $l->t("Export");?>" onclick="window.location='<?php echo OCP\Util::linkTo('calendar', 'export.php') ?>?eventid=<?php echo $_['eventid'] ?>';">
 	</span>
 	</form>
 </div>
diff --git a/apps/calendar/templates/part.newevent.php b/apps/calendar/templates/part.newevent.php
index f4bb867b180a652f12e2909ca8e3a12f0e4f4b04..a4f48aecbc6e9321e94e60cf07e1224ee60daa97 100644
--- a/apps/calendar/templates/part.newevent.php
+++ b/apps/calendar/templates/part.newevent.php
@@ -3,7 +3,7 @@
 <?php echo $this->inc("part.eventform"); ?>
 	<div style="width: 100%;text-align: center;color: #FF1D1D;" id="errorbox"></div>
 	<span id="actions">
-		<input type="button" class="submit" style="float: left;" value="<?php echo $l->t("Submit");?>" onclick="Calendar.UI.validateEventForm('?app=calendar&getfile=ajax/event/new.php');">
+		<input type="button" class="submit" style="float: left;" value="<?php echo $l->t("Submit");?>" onclick="Calendar.UI.validateEventForm('<?php echo OCP\Util::linkTo('calendar', 'ajax/event/new.php') ?>');">
 	</span>
 	</form>
 </div>
diff --git a/apps/gallery/js/pictures.js b/apps/gallery/js/pictures.js
index 91fbf5be967344ce3a0da1687c4adec4da16a8f7..47f727e0deed6ea51acf4bc281ea206d06d3668e 100644
--- a/apps/gallery/js/pictures.js
+++ b/apps/gallery/js/pictures.js
@@ -61,8 +61,8 @@ function deplode(element) {
 
 function openNewGal(album_name) {
 	root = root + decodeURIComponent(album_name) + "/";
-	var url = window.location.toString().replace(window.location.search, '');
-	url = url + "?app=gallery&root="+encodeURIComponent(root);
+	var url = window.location.protocol+"//"+window.location.hostname+OC.linkTo('gallery', 'index.php');
+	url = url + "?root="+encodeURIComponent(root);
 
 	window.location = url;
 }
diff --git a/lib/util.php b/lib/util.php
index 6e62ed9bf58caa645e396241653579c3a49c144f..f26fa63e446342dd221ee39d53801c342bb885a1 100755
--- a/lib/util.php
+++ b/lib/util.php
@@ -343,10 +343,16 @@ class OC_Util {
 			$location = $_REQUEST['redirect_url'];
 		}
 		else if (isset(OC::$REQUESTEDAPP) && !empty(OC::$REQUESTEDAPP)) {
-			$location = OC::$WEBROOT.'/?app='.OC::$REQUESTEDAPP;
+			$location = OC_Helper::linkToAbsolute( OC::$REQUESTEDAPP, 'index.php' );
 		}
 		else {
-			$location = OC::$WEBROOT.'/'.OC_Appconfig::getValue('core', 'defaultpage', '?app=files');
+			$defaultpage = OC_Appconfig::getValue('core', 'defaultpage');
+			if ($defaultpage) {
+				$location = OC_Helper::serverProtocol().'://'.OC_Helper::serverHost().OC::$WEBROOT.'/'.$defaultpage;
+			}
+			else {
+				$location = OC_Helper::linkToAbsolute( 'files', 'index.php' );
+			}
 		}
 		OC_Log::write('core', 'redirectToDefaultPage: '.$location, OC_Log::DEBUG);
 		header( 'Location: '.$location );