diff --git a/content/00-welcome/00-setup.md b/content/00-welcome/00-setup.md
index 8edd144..afd7322 100644
--- a/content/00-welcome/00-setup.md
+++ b/content/00-welcome/00-setup.md
@@ -2,8 +2,6 @@
 
 Congratulations! If you see this page, then the setup of the system has worked successfully!! You can now login (/tm/login) and configure your system, your themes and your plugins. You will find all settings in the settings-area (/tm/settings).
 
-## If it does not work
-
 If you face any problems during the installation, then please make sure, that your system supports these features:
 
 - PHP version 7+.
diff --git a/system/Assets.php b/system/Assets.php
index ad7e83e..1773f3a 100644
--- a/system/Assets.php
+++ b/system/Assets.php
@@ -6,7 +6,7 @@ use Typemill\Models\ProcessImage;
 
 class Assets
 {
-	protected $baseUrl;
+	public $baseUrl;
 	
 	public function __construct($baseUrl)
 	{
@@ -22,6 +22,16 @@ class Assets
 		$this->imageFolder 		= 'original';
 	}
 
+	public function setUri($uri)
+	{
+		$this->uri = $uri;
+	}
+
+	public function setBaseUrl($baseUrl)
+	{
+		$this->baseUrl = $baseUrl;
+	}
+
 	public function image($url)
 	{
 		$this->imageUrl = $url;
@@ -151,6 +161,8 @@ class Assets
 		{
 			$this->JS[] = '<script src="' . $JSfile . '"></script>';
 		}
+
+#		print_r($this->JS);
 	}
 
 	public function addInlineJS($JS)
diff --git a/system/Controllers/ArticleApiController.php b/system/Controllers/ArticleApiController.php
index 351a9de..c0deeca 100644
--- a/system/Controllers/ArticleApiController.php
+++ b/system/Controllers/ArticleApiController.php
@@ -39,6 +39,9 @@ class ArticleApiController extends ContentController
 		# set structure
 		if(!$this->setStructure($draft = true)){ return $response->withJson($this->errors, 404); }
 
+		# set information for homepage
+		$this->setHomepage($args = false);
+
 		# set item 
 		if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
 
@@ -72,7 +75,7 @@ class ArticleApiController extends ContentController
 			if(is_array($this->content))
 			{
 				# initialize parsedown extension
-				$parsedown = new ParsedownExtension();
+				$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
 
 				# turn markdown into an array of markdown-blocks
 				$this->content = $parsedown->arrayBlocksToMarkdown($this->content);				
@@ -125,6 +128,9 @@ class ArticleApiController extends ContentController
 		# set structure
 		if(!$this->setStructure($draft = true)){ return $response->withJson($this->errors, 404); }
 
+		# set information for homepage
+		$this->setHomepage($args = false);
+
 		# set item 
 		if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
 
@@ -151,7 +157,7 @@ class ArticleApiController extends ContentController
 			if(!$this->setContent()){ return $response->withJson($this->errors, 404); }
 			
 			# initialize parsedown extension
-			$parsedown = new ParsedownExtension();
+			$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
 
 			# turn markdown into an array of markdown-blocks
 			$contentArray = $parsedown->markdownToArrayBlocks($this->content);
@@ -219,6 +225,9 @@ class ArticleApiController extends ContentController
 		# set structure
 		if(!$this->setStructure($draft = true)){ return $response->withJson($this->errors, 404); }
 
+		# set information for homepage
+		$this->setHomepage($args = false);
+
 		# set item
 		if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
 		
@@ -237,7 +246,7 @@ class ArticleApiController extends ContentController
 
 		# set redirect url to edit page
 		$url = $this->uri->getBaseUrl() . '/tm/content/' . $this->settings['editor'];
-		if(isset($this->item->urlRelWoF))
+		if(isset($this->item->urlRelWoF) && $this->item->urlRelWoF != '/' )
 		{
 			$url = $url . $this->item->urlRelWoF;
 		}
@@ -276,6 +285,9 @@ class ArticleApiController extends ContentController
 		# set structure
 		if(!$this->setStructure($draft = true)){ return $response->withJson($this->errors, 404); }
 
+		# set information for homepage
+		$this->setHomepage($args = false);
+
 		# set item
 		if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
 
@@ -351,6 +363,9 @@ class ArticleApiController extends ContentController
 		# set structure
 		if(!$this->setStructure($draft = true)){ return $response->withJson($this->errors, 404); }
 
+		# set information for homepage
+		$this->setHomepage($args = false);
+
 		# set item 
 		if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
 
@@ -371,7 +386,7 @@ class ArticleApiController extends ContentController
 		$updatedContent = '# ' . $this->params['title'] . "\r\n\r\n" . $this->params['content'];
 
 		# initialize parsedown extension
-		$parsedown 		= new ParsedownExtension();
+		$parsedown 		= new ParsedownExtension($this->uri->getBaseUrl());
 		
 		# turn markdown into an array of markdown-blocks
 		$contentArray = $parsedown->markdownToArrayBlocks($updatedContent);
@@ -829,7 +844,7 @@ class ArticleApiController extends ContentController
 		if(!$this->setStructure($draft = true, $cache = false)){ return $response->withJson(array('data' => false, 'errors' => $this->errors, 'url' => $url), 404); }
 
 		# set information for homepage
-		$this->setHomepage();
+		$this->setHomepage($args = false);
 
 		# get item for url and set it active again
 		if(isset($this->params['url']))
@@ -854,6 +869,9 @@ class ArticleApiController extends ContentController
 
 		# set structure
 		if(!$this->setStructure($draft = true)){ return $response->withJson(array('data' => false, 'errors' => $this->errors), 404); }
+
+		# set information for homepage
+		$this->setHomepage($args = false);
 		
 		/* set item */
 		if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
@@ -888,7 +906,7 @@ class ArticleApiController extends ContentController
 		if(!is_array($content))
 		{
 			# initialize parsedown extension
-			$parsedown = new ParsedownExtension();
+			$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
 
 			# turn markdown into an array of markdown-blocks
 			$content = $parsedown->markdownToArrayBlocks($content);
@@ -916,6 +934,9 @@ class ArticleApiController extends ContentController
 
 		# set structure
 		if(!$this->setStructure($draft = true)){ return $response->withJson(array('data' => false, 'errors' => $this->errors), 404); }
+
+		# set information for homepage
+		$this->setHomepage($args = false);
 		
 		/* set item */
 		if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
@@ -947,7 +968,7 @@ class ArticleApiController extends ContentController
 		}
 		
 		# initialize parsedown extension
-		$parsedown = new ParsedownExtension();
+		$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
 
 		# fix footnotes in parsedown, might break with complicated footnotes
 		$parsedown->setVisualMode();
diff --git a/system/Controllers/BlockApiController.php b/system/Controllers/BlockApiController.php
index 73b3be6..a9ea0f3 100644
--- a/system/Controllers/BlockApiController.php
+++ b/system/Controllers/BlockApiController.php
@@ -33,6 +33,8 @@ class BlockApiController extends ContentController
 		# set structure
 		if(!$this->setStructure($draft = true)){ return $response->withJson(array('data' => false, 'errors' => $this->errors), 404); }
 		
+		$this->setHomepage($args = false);
+
 		/* set item */
 		if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
 
@@ -72,7 +74,7 @@ class BlockApiController extends ContentController
 		}
 
 		# initialize parsedown extension
-		$parsedown = new ParsedownExtension();
+		$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
 
 		# if content is not an array, then transform it
 		if(!is_array($pageMarkdown))
@@ -170,7 +172,7 @@ class BlockApiController extends ContentController
 		}
 		
 		# initialize parsedown extension
-		$parsedown = new ParsedownExtension();
+		$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
 		
 		# if content is not an array, then transform it
 		if(!is_array($content))
@@ -229,6 +231,8 @@ class BlockApiController extends ContentController
 		# set structure
 		if(!$this->setStructure($draft = true)){ return $response->withJson(array('data' => false, 'errors' => $this->errors), 404); }
 		
+		$this->setHomepage($args = false);
+
 		/* set item */
 		if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
 
@@ -268,7 +272,7 @@ class BlockApiController extends ContentController
 		}
 
 		# initialize parsedown extension
-		$parsedown = new ParsedownExtension();
+		$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
 		$parsedown->setVisualMode();
 
 		# if content is not an array, then transform it
@@ -384,6 +388,8 @@ class BlockApiController extends ContentController
 		# set structure
 		if(!$this->setStructure($draft = true)){ return $response->withJson(array('data' => false, 'errors' => $this->errors), 404); }
 		
+		$this->setHomepage($args = false);
+
 		# set item 
 		if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
 
@@ -415,7 +421,7 @@ class BlockApiController extends ContentController
 		}
 
 		# initialize parsedown extension
-		$parsedown = new ParsedownExtension();
+		$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
 
 		# if content is not an array, then transform it
 		if(!is_array($pageMarkdown))
@@ -490,6 +496,8 @@ class BlockApiController extends ContentController
 		# set structure
 		if(!$this->setStructure($draft = true)){ return $response->withJson(array('data' => false, 'errors' => $this->errors), 404); }
 		
+		$this->setHomepage($args = false);
+		
 		# set item
 		if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
 
@@ -521,7 +529,7 @@ class BlockApiController extends ContentController
 		}
 
 		# initialize parsedown extension
-		$parsedown = new ParsedownExtension();
+		$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
 
 		# if content is not an array, then transform it
 		if(!is_array($this->content))
diff --git a/system/Controllers/ContentBackendController.php b/system/Controllers/ContentBackendController.php
index 9a637ea..9b67d9d 100644
--- a/system/Controllers/ContentBackendController.php
+++ b/system/Controllers/ContentBackendController.php
@@ -28,7 +28,7 @@ class ContentBackendController extends ContentController
 		if(!$this->setStructure($draft = true)){ return $this->renderIntern404($response, array( 'navigation' => true, 'content' => $this->errors )); }
 		
 		# set information for homepage
-		$this->setHomepage();
+		$this->setHomepage($args);
 
 		# set item
 		if(!$this->setItem()){ return $this->renderIntern404($response, array( 'navigation' => $this->structure, 'settings' => $this->settings, 'content' => $this->errors )); }
@@ -44,7 +44,7 @@ class ContentBackendController extends ContentController
 
 		# set path
 		$this->setItemPath($this->item->fileType);
-						
+
 		# add the modified date for the file
 		$this->item->modified	= ($this->item->published OR $this->item->drafted) ? filemtime($this->settings['contentFolder'] . $this->path) : false;
 		
@@ -58,7 +58,7 @@ class ContentBackendController extends ContentController
 		if(is_array($content))
 		{
 			# transform array to markdown
-			$parsedown = new ParsedownExtension();			
+			$parsedown = new ParsedownExtension($this->uri->getBaseUrl());			
 			$content = $parsedown->arrayBlocksToMarkdown($content);
 		}
 
@@ -108,7 +108,7 @@ class ContentBackendController extends ContentController
 		if(!$this->setStructure($draft = true)){ return $this->renderIntern404($response, array( 'navigation' => true, 'content' => $this->errors )); }
 
 		# set information for homepage
-		$this->setHomepage();
+		$this->setHomepage($args);
 
 		# set item
 		if(!$this->setItem()){ return $this->renderIntern404($response, array( 'navigation' => $this->structure, 'settings' => $this->settings, 'content' => $this->errors )); }
@@ -136,7 +136,7 @@ class ContentBackendController extends ContentController
 		}
 		
 		# initialize parsedown extension
-		$parsedown = new ParsedownExtension();
+		$parsedown = new ParsedownExtension($this->uri->getBaseUrl());
 
 		# to fix footnote-logic in parsedown, set visual mode to true
 		$parsedown->setVisualMode();
diff --git a/system/Controllers/ContentController.php b/system/Controllers/ContentController.php
index fe10875..1e2e3b2 100644
--- a/system/Controllers/ContentController.php
+++ b/system/Controllers/ContentController.php
@@ -62,6 +62,8 @@ abstract class ContentController
 		$this->settings				= $this->c->get('settings');
 		$this->structureLiveName 	= 'structure.txt';
 		$this->structureDraftName 	= 'structure-draft.txt';
+
+		$this->c->dispatcher->dispatch('onTwigLoaded');
 	}
 	
 	# admin ui rendering
@@ -275,7 +277,8 @@ abstract class ContentController
 		}
 	}
 
-	protected function setHomepage()
+	# this is only set by content backend controller
+	protected function setHomepage($args)
 	{
 		$contentFolder = Folder::scanFolderFlat($this->settings['rootPath'] . $this->settings['contentFolder']);
 
@@ -295,7 +298,7 @@ abstract class ContentController
 		}
 
 		$active = false;
-		if($this->params['url'] == '/' || $this->params['url'] == $this->uri->getBasePath() )
+		if($this->params['url'] == '/' || (is_array($args) && empty($args)))
 		{
 			$active = 'active';
 		}
@@ -305,8 +308,11 @@ abstract class ContentController
 
 	protected function setItem()
 	{
+		# home is only set by backend controller, not by api calls
+		$home = isset($this->homepage['active']) ? $this->homepage['active'] : false;
+
 		# search for the url in the structure
-		$item = Folder::getItemForUrl($this->structure, $this->params['url'], $this->uri->getBasePath());
+		$item = Folder::getItemForUrl($this->structure, $this->params['url'], $this->uri->getBaseUrl(), NULL, $home);
 
 		if($item)
 		{
diff --git a/system/Controllers/Controller.php b/system/Controllers/Controller.php
index 6dcad45..7dc2064 100644
--- a/system/Controllers/Controller.php
+++ b/system/Controllers/Controller.php
@@ -15,7 +15,8 @@ abstract class Controller
 
 	public function __construct(ContainerInterface $c)
 	{
-		$this->c = $c;
+		$this->c 	= $c;
+		$this->c->dispatcher->dispatch('onTwigLoaded');
 	}
 	
 	# frontend rendering
@@ -23,7 +24,7 @@ abstract class Controller
 	{
 		# why commented this out??
 		$data = $this->c->dispatcher->dispatch('onPageReady', new OnPageReady($data))->getData();
-		
+
 		if(isset($_SESSION['old']))
 		{
 			unset($_SESSION['old']);
diff --git a/system/Controllers/MetaApiController.php b/system/Controllers/MetaApiController.php
index 05dd392..113235e 100644
--- a/system/Controllers/MetaApiController.php
+++ b/system/Controllers/MetaApiController.php
@@ -72,6 +72,9 @@ class MetaApiController extends ContentController
 		# set structure
 		if(!$this->setStructure($draft = true)){ return $response->withJson($this->errors, 404); }
 
+		# set information for homepage
+		$this->setHomepage($args = false);
+
 		# set item 
 		if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
 
@@ -153,6 +156,9 @@ class MetaApiController extends ContentController
 		# set structure
 		if(!$this->setStructure($draft = true)){ return $response->withJson($this->errors, 404); }
 
+		# set information for homepage
+		$this->setHomepage($args);
+
 		# set item 
 		if(!$this->setItem()){ return $response->withJson($this->errors, 404); }
 
diff --git a/system/Controllers/PageController.php b/system/Controllers/PageController.php
index 62bd779..1e22421 100644
--- a/system/Controllers/PageController.php
+++ b/system/Controllers/PageController.php
@@ -106,10 +106,11 @@ class PageController extends Controller
 		}
 
 		# if the user is on startpage
+		$home = false;
 		if(empty($args))
 		{
 			$home = true;
-			$item = Folder::getItemForUrl($navigation, $uri->getBasePath(), $uri->getBasePath());
+			$item = Folder::getItemForUrl($navigation, $uri->getBasePath(), $uri->getBaseUrl(), NULL, $home);
 			$urlRel = $uri->getBasePath();
 		}
 		else
@@ -178,7 +179,7 @@ class PageController extends Controller
 			if(isset($item->hide) && !$item->hide)
 			{
 				# use the navigation instead of the structure so that hidden elements are erased
-				$item = Folder::getItemForUrl($navigation, $urlRel, $uri->getBasePath());
+				$item = Folder::getItemForUrl($navigation, $urlRel, $uri->getBaseUrl(), NULL, $home);
 			}
 		}
 
@@ -200,7 +201,7 @@ class PageController extends Controller
 		$itemUrl 		= isset($item->urlRel) ? $item->urlRel : false;
 
 		/* initialize parsedown */
-		$parsedown 		= new ParsedownExtension($settings['headlineanchors']);
+		$parsedown 		= new ParsedownExtension($base_url, $settings['headlineanchors']);
 		
 		/* set safe mode to escape javascript and html in markdown */
 		$parsedown->setSafeMode(true);
diff --git a/system/Extensions/ParsedownExtension.php b/system/Extensions/ParsedownExtension.php
index e38d6bc..65a28bb 100644
--- a/system/Extensions/ParsedownExtension.php
+++ b/system/Extensions/ParsedownExtension.php
@@ -6,7 +6,7 @@ use \URLify;
 
 class ParsedownExtension extends \ParsedownExtra
 {
-    function __construct($showAnchor = NULL, $skipAbsoluteUrls = NULL)
+    function __construct($baseUrl = '', $showAnchor = NULL)
     {
         parent::__construct();
 
@@ -14,7 +14,7 @@ class ParsedownExtension extends \ParsedownExtra
         $this->showAnchor = $showAnchor;
 
         # base url is needed for media/images and relative links (e.g. if www.mydomain.com/mywebsite)
-        $this->baseUrl = $skipAbsoluteUrls ? '' : TM_BASE_URL;
+        $this->baseUrl = $baseUrl;
 
         # math support
         $this->BlockTypes['\\'][] = 'Math';
diff --git a/system/Middleware/assetMiddleware.php b/system/Middleware/assetMiddleware.php
new file mode 100644
index 0000000..46b9dfc
--- /dev/null
+++ b/system/Middleware/assetMiddleware.php
@@ -0,0 +1,40 @@
+<?php
+
+namespace Typemill\Middleware;
+
+use Slim\Views\Twig;
+use Slim\Http\Request;
+use Slim\Http\Response;
+
+class assetMiddleware
+{
+    protected $view;
+    protected $c;
+    
+    public function __construct($container)
+    {
+        # $this->view = $view;
+        $this->container = $container;
+    }
+    
+    public function __invoke(Request $request, Response $response, $next)
+    {
+
+    	# get the uri after proxy detection
+        $uri 	= $request->getUri()->withUserInfo('');
+
+		# update the asset object in the container (for plugins) with the new url
+		$this->container->assets->setBaseUrl($uri->getBaseUrl());
+
+        # add the asset object to twig-frontend for themes
+        $this->container['view']->getEnvironment()->addGlobal('assets', $this->container['assets']);
+        
+        # use {{ base_url() }} in twig templates
+		$this->container['view']['base_url']	 	= $uri->getBaseUrl();
+		$this->container['view']['current_url'] 	= $uri->getPath();
+
+	    $response = $next($request, $response);
+	    
+	    return $response;
+    }
+}
\ No newline at end of file
diff --git a/system/Models/Folder.php b/system/Models/Folder.php
index 53e2541..1df2d86 100644
--- a/system/Models/Folder.php
+++ b/system/Models/Folder.php
@@ -267,11 +267,11 @@ class Folder
 		}
 	}
 
-	public static function getItemForUrl($folderContentDetails, $url, $baseUrl, $result = NULL)
+	public static function getItemForUrl($folderContentDetails, $url, $baseUrl, $result = NULL, $home = NULL )
 	{
 
 		# if we are on the homepage
-		if($url == '/' OR $url == $baseUrl)
+		if($home)
 		{
 			# return a standard item-object
 			$item 					= new \stdClass;
diff --git a/system/Plugin.php b/system/Plugin.php
index 2ec3eaa..329e0e5 100644
--- a/system/Plugin.php
+++ b/system/Plugin.php
@@ -49,7 +49,7 @@ abstract class Plugin implements EventSubscriberInterface
             ->withHeader("Content-Type", "application/json")
             ->withStatus(400)
             ->write(json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
-    }    
+    }
 	
 	protected function getSettings()
 	{
diff --git a/system/system.php b/system/system.php
index ec5abfe..afac40e 100644
--- a/system/system.php
+++ b/system/system.php
@@ -42,23 +42,19 @@ if($settings['settings']['displayErrorDetails'])
 
 $app = new \Slim\App($settings);
 
-
-/************************
-*  ADD PROXY DETECTION	*
-************************/
-
-if(isset($settings['settings']['proxy']) && $settings['settings']['proxy'])
-{
-	$trustedProxies = ( isset($settings['settings']['trustedproxies']) && !empty($settings['settings']['trustedproxies']) ) ? explode(",", $settings['settings']['trustedproxies']) : [];
-	$app->add(new RKA\Middleware\ProxyDetection($trustedProxies));
-}
-
 /************************
 *  GET SLIM CONTAINER	*
 ************************/
 
 $container = $app->getContainer();
 
+/************************
+* Create URI 			*
+************************/
+
+# get uri and delete username and password from uri
+$uri = \Slim\Http\Uri::createFromEnvironment(new \Slim\Http\Environment($_SERVER))->withUserInfo('');
+
 /************************
 * LOAD & UPDATE PLUGINS *
 ************************/
@@ -157,20 +153,6 @@ $container['dispatcher'] = function($container) use ($dispatcher)
 	return $dispatcher;
 };
 
-# delete username and password from uri
-$uri = $container['request']->getUri()->withUserInfo('');
-
-define("TM_BASE_URL", $uri->getBaseUrl());
-
-/********************************
-* ADD ASSET-FUNCTION FOR TWIG	*
-********************************/
-
-$container['assets'] = function($c) use ($uri)
-{
-	return new \Typemill\Assets($uri->getBaseUrl());
-};
-
 /************************
 * 	DECIDE FOR SESSION	*
 ************************/
@@ -181,20 +163,32 @@ $session_segments 	= array('setup', 'tm/', 'api/', '/setup', '/tm/', '/api/');
 $client_segments 	= $dispatcher->dispatch('onSessionSegmentsLoaded', new OnSessionSegmentsLoaded([]))->getData();
 $session_segments	= array_merge($session_segments, $client_segments);
 
-$path 				= $uri->getPath();
 $container['flash']	= false;
 $container['csrf'] 	= false;
 
+
+/************************************
+* ADD ASSET-FUNCTION FOR PLUGINS	*
+************************************/
+
+$container['assets'] = function($c) use ($uri)
+{
+	return new \Typemill\Assets($uri->getBaseUrl());
+};
+
+/********************************
+*  MOVE TO MIDDLEWARE NEXT TIME *
+********************************/
+
 # if website is restricted to registered user
 if(isset($settings['settings']['access']) && $settings['settings']['access'] == 'registered')
 {
 	# activate session for all routes
-	$session_segments = [$path];
+	$session_segments = [$uri->getPath()];
 }
-
 foreach($session_segments as $segment)
 {
-	if(substr( $path, 0, strlen($segment) ) === $segment)
+	if(substr( $uri->getPath(), 0, strlen($segment) ) === $segment)
 	{	
 		// configure session
 		ini_set('session.cookie_httponly', 1 );
@@ -245,9 +239,13 @@ $container['view'] = function ($container) use ($uri)
 		'debug' => true
     ]);
     
-    // Instantiate and add Slim specific extension
-    $basePath = rtrim(str_ireplace('index.php', '', $uri->getBasePath()), '/');
-    $view->addExtension(new Slim\Views\TwigExtension($container['router'], $basePath));
+    # Instantiate and add Slim specific extension
+    $router = $container->get('router');
+
+#    $basePath = rtrim(str_ireplace('index.php', '', $uri->getBasePath()), '/');
+#    $view->addExtension(new Slim\Views\TwigExtension($container['router'], $basePath));
+
+    $view->addExtension(new Slim\Views\TwigExtension($router, $uri));
 	$view->addExtension(new Twig_Extension_Debug());
     $view->addExtension(new Typemill\Extensions\TwigUserExtension());
 	$view->addExtension(new Typemill\Extensions\TwigMarkdownExtension());
@@ -255,34 +253,27 @@ $container['view'] = function ($container) use ($uri)
 	$view->addExtension(new Typemill\Extensions\TwigPagelistExtension());	
 
 	# use {{ base_url() }} in twig templates
-	$view['base_url']	 = $uri->getBaseUrl();
-	$view['current_url'] = $uri->getPath();
+#	$view['base_url']	 = $uri->getBaseUrl();
+#	$view['current_url'] = $uri->getPath();
 
-	/* if session route, add flash messages and csrf-protection */
+	# if session route, add flash messages and csrf-protection
 	if($container['flash'])
 	{
 		$view->getEnvironment()->addGlobal('flash', $container->flash);
 		$view->addExtension(new Typemill\Extensions\TwigCsrfExtension($container['csrf']));
 	}
 
-	/* add asset-function to all views */
-	$view->getEnvironment()->addGlobal('assets', $container->assets);
-
 	/******************************
 	* LOAD TRANSLATIONS           *
 	******************************/
-  	$uri = $_SERVER['REQUEST_URI'];
-
-    $base_path = $container['request']->getUri()->getBasePath();
-    $uri = str_replace($base_path,'',$uri);
-    $pieces = explode('/',$uri);
-    if(isset($uri) && ($pieces[1] === 'tm' OR $pieces[1] === 'setup') )
+    $pieces = explode('/',$uri->getPath());
+    if( ($pieces[0] === 'tm' OR $pieces[0] === 'setup') )
   	{
-    	// Admin environment labels
+    	# Admin environment labels
     	$labels = Typemill\Translations::loadTranslations('admin');
   	} else {
-    	// User environment labels
-    	// For now it is useless, but it will prove useful in the future
+    	# User environment labels
+    	# For now it is useless, but it will prove useful in the future
     	$labels = Typemill\Translations::loadTranslations('user');
   	}
   	$view['translations'] = $labels;
@@ -291,7 +282,7 @@ $container['view'] = function ($container) use ($uri)
 	return $view;
 };
 
-$container->dispatcher->dispatch('onTwigLoaded');
+# $container->dispatcher->dispatch('onTwigLoaded');
 
 /***************************
 * 	ADD NOT FOUND HANDLER  *
@@ -323,6 +314,22 @@ if($container['flash'])
 	$app->add($container->get('csrf'));	
 }
 
+/********************************
+*  ASSET MIDDLEWARE FOR TWIG	*
+********************************/
+
+$app->add(new \Typemill\Middleware\assetMiddleware($container));
+
+/********************************
+*  PROXY DETECTION FOR REQUEST	*
+********************************/
+
+if(isset($settings['settings']['proxy']) && $settings['settings']['proxy'])
+{
+	$trustedProxies = ( isset($settings['settings']['trustedproxies']) && !empty($settings['settings']['trustedproxies']) ) ? explode(",", $settings['settings']['trustedproxies']) : [];
+	$app->add(new RKA\Middleware\ProxyDetection($trustedProxies));	
+}
+
 /************************
 * 	ADD ROUTES			*
 ************************/
diff --git a/themes/cyanine/home/landingpageNews.twig b/themes/cyanine/home/landingpageNews.twig
index 6cf9218..2edc20f 100644
--- a/themes/cyanine/home/landingpageNews.twig
+++ b/themes/cyanine/home/landingpageNews.twig
@@ -17,7 +17,7 @@
 						<li class="db list tl pa0 w-100 mh0 mv2 mh2-l shadow-2-hover">
 							<a class="link mv4 dim" href="{{ element.urlAbs }}">
 								<div class="db h4-5 overflow-hidden">
-									<img class="db w-100" src="{{ page.meta.heroimage }}" alt="{{ page.meta.heroimagealt }}">
+									<img class="db w-100" src="{{base_url}}/{{ page.meta.heroimage }}" alt="{{ page.meta.heroimagealt }}">
 								</div>
 								<div class="pa2 ph3-ns pb3-ns">
 									<h3>{{ page.meta.title }}</h3>
@@ -43,7 +43,7 @@
 
 							<a class="link mv4 dim" href="{{ element.urlAbs }}">
 								<div class="db h4-5 overflow-hidden">
-									<img class="db w-100" src="{{ post.meta.heroimage }}" alt="{{ post.meta.heroimagealt }}">
+									<img class="db w-100" src="{{base_url}}/{{ post.meta.heroimage }}" alt="{{ post.meta.heroimagealt }}">
 								</div>
 								<div class="pa2 ph3-ns pb3-ns">
 									<h3>{{ post.meta.title }}</h3>