代码之家  ›  专栏  ›  技术社区  ›  Dennis

我如何编写一个Zend Framework应用程序,直接为请求提供服务(将URL映射到文件)?

  •  0
  • Dennis  · 技术社区  · 7 年前

    背景:我有一个遗留应用程序,可以按原样提供文件。也就是说,当我去 http://server/subfolder/my_index.php?value=x 它进入 subfolder my_index.php

    有办法吗?

    不确定这是否是一种方法,但我在这里研究了中间件层:

    我不清楚如何使用它们,以及它们是否会帮助我。

    namespace Application\Middleware;
    
    use Psr\Http\Message\ServerRequestInterface;
    use Interop\Http\ServerMiddleware\MiddlewareInterface;
    use Interop\Http\ServerMiddleware\DelegateInterface;
    use Zend\Http\Response;
    
    class IndexMiddleware implements MiddlewareInterface
    {
    
        public function process(ServerRequestInterface $request, DelegateInterface $delegate)
        {
            $response = new \Zend\Diactoros\Response();
            return $response;
        }
    }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Thomas Dutrion    7 年前

    如果你看看你的 .htaccess

    RewriteEngine On
    # The following rule tells Apache that if the requested filename
    # exists, simply serve it.
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [L]
    # The following rewrites all other queries to index.php. The 
    # condition ensures that if you are using Apache aliases to do
    # mass virtual hosting or installed the project in a subdirectory,
    # the base path will be prepended to allow proper resolution of
    # the index.php file; it will work in non-aliased environments
    # as well, providing a safe, one-size fits all solution.
    RewriteCond %{REQUEST_URI}::$1 ^(/.+)/(.*)::\2$
    RewriteRule ^(.*) - [E=BASE:%1]
    RewriteRule ^(.*)$ %{ENV:BASE}/index.php [L]