private function filterHrefWithPath($matches) {

		static $script;
		static $observeRewrite;
		static $config;
		static $assetsPath;

		if(is_null($config)) {
			$application = Application::getInstance();

			$config = $application->getConfig();
			$observeRewrite = $application->getRouter()->getServerSideRewrite();
		}

		if(is_null($script)) {
			$script = basename(trim(Request::createFromGlobals()->getScriptName(), '/'));
		}

		$matchSegments = explode('/', $matches[3]);
		$pathToFind = array_shift($matchSegments);
		
		$recursiveFind = function(Menu $m) use (&$recursiveFind, $pathToFind) {

			foreach($m->getEntries() as $e) {

				if($e->getPath() === $pathToFind) {
					return $e;
				}

				if(($sm = $e->getSubMenu()) && $sm->getType() !== 'dynamic') {
					if($e = $recursiveFind($sm)) {
						return $e;
					}
				}
			}

		};

		foreach($config->menus as $menu) {
			if($menu->getScript() === $script) {
				if(($e = $recursiveFind($menu))) {
					break;
				}
			}
		}

		if(isset($e)) {

			$pathSegments = [$e->getPath()];

			while($e = $e->getMenu()->getParentEntry()) {
				$pathSegments[] = $e->getPath();
			}

			$uriParts = [];

			if($observeRewrite) {
				if($script !== 'index.php') {
					$uriParts[] = basename($script, '.php');
				}
			}
			else {
				if(is_null($assetsPath)) {
					$assetsPath = Application::getInstance()->getRelativeAssetsPath();
				}

				$uriParts[] = ltrim($assetsPath, '/') . $script;
			}
			if(count($pathSegments)) {
				$uriParts[] = implode('/', array_reverse($pathSegments));
			}
			if(count($matchSegments)) {
				$uriParts[] = implode('/', $matchSegments);
			}

			$uri = implode('/', $uriParts) . $matches[4];

			return "<a{$matches[1]} href={$matches[2]}/$uri{$matches[2]}{$matches[5]}>";

		}
	}