protected function resolveRealUrl($fileName)
    {
        $fileNameClean = str_replace("\0", '', $fileName);
        $realPath = realpath($fileNameClean);

        if ($realPath === false) {
            // the page doesn't exist or realpath failed
            return $this->requestUrl;
        }
        
        // Get Pico content path and file extension
        $contentPath = realpath($this->pico->getConfig('content_dir'));
        $contentExt = $this->pico->getConfig('content_ext');
        
        if (strpos($realPath, $contentPath) !== 0) {
            // The file is not inside the content path (symbolic link)
            throw new \RuntimeException("The plugin cannot be used with "
                . "symbolic links inside the content directory.");
        }

        // Get a relative path of $realPath from inside the $contentPath and remove an extension
        // len+1 to remove trailing path delimeter, which $contentPath doesn't have
        $name = substr($realPath, strlen($contentPath)+1, -strlen($contentExt));
        
        // Always use forward slashes
        if (DIRECTORY_SEPARATOR !== '/') {
            $name = str_replace(DIRECTORY_SEPARATOR, '/', $name);
        }
        
        // If the name ends with "/index", remove it, for the main page returns ""
        if (strlen($name) >= 5 && 0 === substr_compare($name, "index", -5)) {
            $name= rtrim(substr($name, 0, -5), '/');
        }
        
        return $name;
    }