public static function linkRewrite($str, $allowUnicodeChars = false)
    {
        if (!\is_string($str)) {
            return false;
        }

        $str = trim($str);

        if (\function_exists('mb_strtolower')) {
            $str = mb_strtolower($str, 'utf-8');
        }
        if (!$allowUnicodeChars) {
            $str = self::replaceAccentedChars($str);
        }

        // Remove all non-whitelist chars.
        if ($allowUnicodeChars) {
            $str = preg_replace('/[^a-zA-Z0-9\s\'\:\/\[\]\-\pL]/u', '', $str);
        } else {
            $str = preg_replace('/[^a-zA-Z0-9\s\'\:\/\[\]\-]/', '', $str);
        }

        $str = preg_replace('/[\s\'\:\/\[\]\-]+/', ' ', $str);
        $str = str_replace([' ', '/'], '-', $str);

        // If it was not possible to lowercase the string with mb_strtolower, we do it after the transformations.
        // This way we lose fewer special chars.
        if (!\function_exists('mb_strtolower')) {
            $str = strtolower($str);
        }

        return $str;
    }