在 apache 上设置虚拟主机,以允许 Zend 与另一个应用程序/静态网站位于同一域


Set up virtual host on apache to allow Zend on same domain as another application / static website

目标是有效地在与静态网站相同的域上设置Zend应用程序。目前,以下内容为真,但速度很慢:

  • www.website.com/重定向至 www.website.com/corp/index.html
  • /admin,/login,/session 解析为/index.php zend 应用程序所在的位置

我已经在我的引导程序中设置了重定向到 www.website.com/corp/index.html,但无论我访问哪个页面,都必须在适当的时候进行此重定向。它正在减慢整个静态站点的速度。这是我的虚拟主机 httpd.conf 条目,它将所有内容重定向到/index.php但我想放置一个例外,一旦您进入该目录,它就允许在没有重定向的情况下访问/corp。其他简单有效的解决方案当然也受到欢迎。

<VirtualHost *:18887>
   DocumentRoot c:'pathtoapp'public
   ServerName website.com
    SetEnv APPLICATION_ENV "local"
     <Directory c:'pathtoapp'public>
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

如果你修改Zend Framework的.htaccess文件以绕过向前端控制器发送任何请求/corp/*,你应该能够绕过这个问题。

尝试将公共目录中的.htaccess文件更改为以下内容:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} ^corp'/* [OR]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

第一个 RewriteCond 检查请求文件名是否与/corp/*匹配,如果匹配,则绕过前端控制器并直接通过 Apache 为请求提供服务,并且您的 Zend 应用程序永远不必处理任何这些请求。