public function rewriteUrl(array $aMatches, \AssetsBundle\AssetFile\AssetFile $oAssetFile)
    {
        if (!isset($aMatches[1])) {
            throw new \InvalidArgumentException('Url match is not valid');
        }

        // Remove quotes & double quotes from url
        $aFirstCharMatches = null;
        $sFirstChar = preg_match('/^("|\'){1}/', $sUrl = trim($aMatches[1]), $aFirstCharMatches) ? $aFirstCharMatches[1] : '';
        $sUrl = str_ireplace(array('"', '\''), '', $sUrl);

        // Data url
        if (strpos($sUrl, 'data:') === 0) {
            return $aMatches[0];
        }

        // Remote absolute url
        if (preg_match('/^http/', $sUrl)) {
            return $aMatches[0];
        }

        // Split arguments
        if (strpos($sUrl, '?') !== false) {
            list($sUrl, $sArguments) = explode('?', $sUrl);
        }

        // Split anchor
        if (strpos($sUrl, '#') !== false) {
            list($sUrl, $sAnchor) = explode('#', $sUrl);
        }

        // Absolute url
        if (($sUrlRealpath = $this->getOptions()->getRealPath($sUrl, $oAssetFile))) {
            // Initialize asset file from url
            $oUrlAssetFile = new \AssetsBundle\AssetFile\AssetFile(array(
                'asset_file_type' => \AssetsBundle\AssetFile\AssetFile::ASSET_MEDIA,
                'asset_file_path' => $sUrlRealpath
            ));

            $sAssetFileCachePath = $this->getAssetFilesCacheManager()->getAssetFileCachePath($oUrlAssetFile);
            if (!file_exists($sAssetFileCachePath)) {
                throw new \LogicException('Media file "' . $oUrlAssetFile->getAssetFilePath() . '" used by "' . $oAssetFile->getAssetFilePath() . '" does not have been cached. Please add it into ["assets_bundle"]["assets"]["media"] configuration array');
            }

            // Define cached file path
            $oUrlAssetFile->setAssetFilePath($sAssetFileCachePath);

            // Retrieve asset file base url
            $sAssetFileBaseUrl = $this->getOptions()->getAssetFileBaseUrl($oUrlAssetFile);

            // Add argument and / or anchor to asset file base url
            $sAssetFileRealBaseUrl = $sFirstChar . $sAssetFileBaseUrl . (empty($sArguments) ? '' : '?' . $sArguments) . (empty($sAnchor) ? '' : '#' . $sAnchor) . $sFirstChar;

            // Return asset file base url
            return str_replace($aMatches[1], $sAssetFileRealBaseUrl, $aMatches[0]);
        } // Remote relative url
        elseif ($oAssetFile->isAssetFilePathUrl()) {
            return str_replace($aMatches[1], $sFirstChar . dirname($oAssetFile->getAssetFilePath()) . '/' . ltrim($sUrl, '/') . $sFirstChar, $aMatches[0]);
        } // Url is not an exising file
        else {
            throw new \LogicException('Url file "' . $sUrl . '" does not exist even relative with "' . $oAssetFile->getAssetFilePath() . '"');
        }
    }