diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php
index 43127d9a0dc64c70db17b96c331109ca39054fa0..097015dd9090fcb8583d658ad8d4cc9a92288a85 100644
--- a/lib/SimpleSAML/XHTML/Template.php
+++ b/lib/SimpleSAML/XHTML/Template.php
@@ -297,6 +297,7 @@ class Template extends Response
         $twig->addGlobal('queryParams', $queryParams);
         $twig->addGlobal('templateId', str_replace('.twig', '', $this->normalizeTemplateName($this->template)));
         $twig->addGlobal('isProduction', $this->configuration->getBoolean('production', true));
+        $twig->addGlobal('baseurlpath', ltrim($this->configuration->getBasePath(), '/'));
 
         // add a filter for translations out of arrays
         $twig->addFilter(
diff --git a/modules/adfs/templates/postResponse.twig b/modules/adfs/templates/postResponse.twig
index 857aa8d7ab6fcd28e21630ea84031a22452840a4..16f0eab1802ea633b8da3d64a1a3376b9ee52bef 100644
--- a/modules/adfs/templates/postResponse.twig
+++ b/modules/adfs/templates/postResponse.twig
@@ -1,7 +1,7 @@
 <!DOCTYPE html>
 <html>
     <head>
-        <script src="{{ baseurlpath }}/assets/js/postResponse.js"></script>
+        <script src="/{{ baseurlpath }}module.php/adfs/assets/js/postResponse.js"></script>
     </head>
     <body>
         <form method="post" action="{{ url }}">
diff --git a/modules/authYubiKey/templates/yubikeylogin.twig b/modules/authYubiKey/templates/yubikeylogin.twig
index 8fa4385f21dfba30141035b379d0b5793764b82e..cedb3f703c3acff864cf0b0ba1790965d408b466 100644
--- a/modules/authYubiKey/templates/yubikeylogin.twig
+++ b/modules/authYubiKey/templates/yubikeylogin.twig
@@ -2,11 +2,11 @@
 {% extends "base.twig" %}
 
 {% block preload %}
-    <link rel="stylesheet" type="text/css" href="{{ baseurlpath }}assets/css/yubikey.css">
+    <link rel="stylesheet" href="/{{ baseurlpath }}module.php/authYubiKey/assets/css/yubikey.css">
 {% endblock %}
 
 {% block postload %}
-    <script src="{{ baseurlpath }}assets/js/autofocus.js"></script>
+    <script src="/{{ baseurlpath }}module.php/authYubiKey/assets/js/autofocus.js"></script>
 {% endblock %}
 
 {% block content %}
diff --git a/modules/consent/templates/consentform.twig b/modules/consent/templates/consentform.twig
index b1433046a9e07af6757ec0453c9b2c14c715f98b..c8084207d2df6c190f78e2afa93391c17ed4f025 100644
--- a/modules/consent/templates/consentform.twig
+++ b/modules/consent/templates/consentform.twig
@@ -2,7 +2,7 @@
 {% extends "base.twig" %}
 
 {% block preload %}
-<link rel="stylesheet" type="text/css" href="{{ baseurlpath }}assets/css/consent.css" />
+<link rel="stylesheet" href="/{{ baseurlpath }}module.php/consent/assets/css/consent.css">
 {% endblock %}
 
 {% block content %}
diff --git a/modules/consentAdmin/templates/consentadmin.twig b/modules/consentAdmin/templates/consentadmin.twig
index d27b8a63d399432c22585deb97e35d6aa7f54156..aa1e81ff42580b74a9f54d84673f6f9fa053cf43 100644
--- a/modules/consentAdmin/templates/consentadmin.twig
+++ b/modules/consentAdmin/templates/consentadmin.twig
@@ -2,11 +2,11 @@
 {% extends "base.twig" %}
 
 {% block preload %}
-<link rel="stylesheet" type="text/css" href="{{ basepathurl }}assets/css/consentAdmin.css" />
+<link rel="stylesheet" href="/{{ baseurlpath }}module.php/consentAdmin/assets/css/consentAdmin.css">
 {% endblock %}
 
 {% block postload %}
-<script src="{{ baseurlpath }}assets/js/consentAdmin.js"></script>
+<script src="/{{ baseurlpath }}module.php/consentAdmin/assets/js/consentAdmin.js"></script>
 {% endblock %}
 
 {% block content %}
@@ -77,6 +77,6 @@
 <p>{{ '{consentAdmin:consentadmin:consentadmin_description2}'|trans|raw }}</p>
 
 <h2>Logout</h2>
-<p><a href="{{ baseurlpath }}consentAdmin.php?logout=1">Logout</a></p>
+<p><a href="/{{ baseurlpath }}module.php/consentAdmin/consentAdmin.php?logout=1">Logout</a></p>
 
 {% endblock %}
diff --git a/modules/cron/templates/croninfo.twig b/modules/cron/templates/croninfo.twig
index b00b8905b8ab2107cb0c9d1980dc0a7fea539ea4..d2ea32988d69d46edbd58b76d1e48de895df60f2 100644
--- a/modules/cron/templates/croninfo.twig
+++ b/modules/cron/templates/croninfo.twig
@@ -2,7 +2,7 @@
 {% extends "base.twig" %}
 
 {% block preload %}
-<link rel="stylesheet" type="text/css" href="{{ baseurlpath }}assets/css/cron.css">
+<link rel="stylesheet" href="/{{ baseurlpath }}module.php/cron/assets/css/cron.css">
 {% endblock %}
 
 {% block content %}
diff --git a/modules/discopower/templates/disco.twig b/modules/discopower/templates/disco.twig
index 5fd06df1b6e1a54799165b39bccfb6ce77dd2462..bd72483935347cd5dff98220a5f1c082fb9c5108 100644
--- a/modules/discopower/templates/disco.twig
+++ b/modules/discopower/templates/disco.twig
@@ -2,14 +2,13 @@
 {% extends "base.twig" %}
 
 {% block preload %}
-    <link href="{{ baseurlpath }}style.css" rel="stylesheet" type="text/css" media="screen" />
-    <link rel="stylesheet" media="screen" type="text/css" href="/resources/uitheme1.8/jquery-ui.css" />
+    <link rel="stylesheet" media="screen" href="/{{ baseurlpath }}resources/uitheme1.8/jquery-ui.css">
 {% endblock %}
 {% block postload %}
-    <script type="text/javascript" src="/resources/jquery-1.8.js"></script>
-    <script type="text/javascript" src="/resources/jquery-ui-1.8.js"></script>
-    <script type="text/javascript" src="{{ baseurlpath }}js/jquery.livesearch.js"></script>
-    <script type="text/javascript" src="{{ baseurlpath }}js/{{ score }}.js"></script>
+    <script src="/{{ baseurlpath }}resources/jquery-1.8.js"></script>
+    <script src="/{{ baseurlpath }}resources/jquery-ui-1.8.js"></script>
+    <script src="/{{ baseurlpath }}module.php/discopower/js/jquery.livesearch.js"></script>
+    <script src="/{{ baseurlpath }}module.php/discopower/js/{{ score }}.js"></script>
     {{ search|raw }}
 {% endblock %}
 
diff --git a/modules/memcacheMonitor/templates/memcachestat.twig b/modules/memcacheMonitor/templates/memcachestat.twig
index fdc4af4bd03a307ad28974a4c4463185ec4ab749..f14848515f513d022a887d2f704d6e791279cd37 100644
--- a/modules/memcacheMonitor/templates/memcachestat.twig
+++ b/modules/memcacheMonitor/templates/memcachestat.twig
@@ -2,7 +2,7 @@
 {% extends "base.twig" %}
 
 {% block preload %}
-    <link href="{{ baseurlpath }}assets/css/memcacheMonitor.css" rel="stylesheet" />
+    <link href="/{{ baseurlpath }}module.php/memcacheMonitor/assets/css/memcacheMonitor.css" rel="stylesheet">
 {% endblock %}
 
 {% block content %}
diff --git a/modules/negotiate/templates/redirect.twig b/modules/negotiate/templates/redirect.twig
index 3a69556eec3127cc60c5dec5ab09fac27d970857..f8162a40101b35bf4ec7c62e7d61f8c05a43f429 100644
--- a/modules/negotiate/templates/redirect.twig
+++ b/modules/negotiate/templates/redirect.twig
@@ -1,7 +1,7 @@
 <!DOCTYPE HTML>
 <html lang="en-US">
     <head>
-        <script src="{{ baseurlpath }}/assets/js/redirect.js"></script>
+        <script src="/{{ baseurlpath }}modules.php/negotiate/assets/js/redirect.js"></script>
         <title>Redirect to login</title>
     </head>
     <body>
diff --git a/modules/statistics/templates/statistics.twig b/modules/statistics/templates/statistics.twig
index bcd02a049d0af5e508ac703ffb4413631700a13c..fa6559e3afe8e4c4931230c0d84404ab07a88dc0 100644
--- a/modules/statistics/templates/statistics.twig
+++ b/modules/statistics/templates/statistics.twig
@@ -2,14 +2,14 @@
 {% extends "base.twig" %}
 
 {% block preload %}
-    <link href="{{ baseurlpath }}assets/css/statistics.css" rel="stylesheet" />
-    <link rel="stylesheet" media="screen" type="text/css" href="/resources/uitheme1.8/jquery-ui.css" />
+    <link href="/{{ baseurlpath }}module.php/statistics/assets/css/statistics.css" rel="stylesheet">
+    <link rel="stylesheet" media="screen" href="/{{ baseurlpath }}resources/uitheme1.8/jquery-ui.css">
 {% endblock %}
 
 {% block postload %}
-<script type="text/javascript" src="/resources/jquery-1.8.js"></script>
-<script type="text/javascript" src="/resources/jquery-ui-1.8.js"></script>
-<script type="text/javascript" src="{{ baseurlpath }}assets/js/statistics.js"></script>
+<script src="/{{ baseurlpath }}resources/jquery-1.8.js"></script>
+<script src="/{{ baseurlpath }}resources/jquery-ui-1.8.js"></script>
+<script src="/{{ baseurlpath }}module.php/statistics/assets/js/statistics.js"></script>
 {% endblock %}
 
 {% block content %}
diff --git a/modules/statistics/templates/statmeta.twig b/modules/statistics/templates/statmeta.twig
index 09808e837a0d97818e143582d9915199cfe24d43..314a21b510774bd517e3760d2bf4d1ab07b2bdb8 100644
--- a/modules/statistics/templates/statmeta.twig
+++ b/modules/statistics/templates/statmeta.twig
@@ -2,7 +2,7 @@
 {% extends "base.twig" %}
 
 {% block preload %}
-    <link href="{{ baseurlpath }}assets/css/statistics.css" rel="stylesheet" />
+    <link href="/{{ baseurlpath }}modules.php/statistics/assets/css/statistics.css" rel="stylesheet">
 {% endblock %}
 
 {% block content %}
@@ -35,5 +35,5 @@
         <tr><td>No metadata found</td></tr>
     {% endif %}
     </table>
-    <p>[ <a href="{{ baseurlpath }}showstats.php">Show statistics</a> ]</p>
+    <p>[ <a href="/{{ baseurlpath }}module.php/statistics/showstats.php">Show statistics</a> ]</p>
 {% endblock %}
diff --git a/templates/base.twig b/templates/base.twig
index 29228797c37b932ecba2ae862f9a17ad32818f41..e33257b76a6cd95e3490213288b142d2d90f415d 100644
--- a/templates/base.twig
+++ b/templates/base.twig
@@ -4,11 +4,11 @@
     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     <meta name="viewport" content="initial-scale=1.0">
     <title>{{ pagetitle }}</title>
-    <link rel="stylesheet" type="text/css" href="{{ asset("css/stylesheet.css") }}">
-    <link rel="icon" type="image/icon" href="/{{ baseurlpath }}resources/icons/favicon.ico">
+    <link rel="stylesheet" href="{{ asset("css/stylesheet.css") }}">
+    <link rel="icon" href="/{{ baseurlpath }}resources/icons/favicon.ico">
     {% if isRTL %}
 
-    <link rel="stylesheet" type="text/css" href="/{{ baseurlpath }}assets/css/src/default-rtl.css" />
+    <link rel="stylesheet" href="{{ asset("assets/css/src/default-rtl.css") }}">
     {% endif %}
 
     <meta name="robots" content="noindex, nofollow">