private function getFilename(RequestInterface $request, $indexExt = 'html')
    {
        $path = urldecode($request->getUri()->getPath());
        $parts = pathinfo($path);
        $path = isset($parts['dirname']) ? $parts['dirname'] : '';
        $filename = isset($parts['basename']) ? $parts['basename'] : '';

        //if it's a directory, append the index file
        if (empty($parts['extension'])) {
            $filename .= "/index.{$indexExt}";
        }

        if ($this->appendQuery && $request->getUri()->getQuery()) {
            $filename .= '?'.urlencode($request->getUri()->getQuery());
        }

        return Helpers::joinPath($this->directory, $path, $filename);
    }