0

我有一个默认的 Zend Framework 应用程序安装在/var/www/html/zend_example. 公共目录是:/var/www/html/zend_example/public.

我也有其他非 Zend 站点/var/www/html。例如,/var/www/html/other_site

如何配置 ZF 站点以在其下工作http://MYDOMAIN/zend_example同时允许http://MYDOMAIN/other_site工作?

这是我的 apache 配置文件:

<VirtualHost *:80>
    DocumentRoot /var/www/html/zend_example/public
    SetEnv APPLICATION_ENV "development"
    <Directory /var/www/html/zend_example/public>
        DirectoryIndex index.php
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

这是中的.htaccess文件/var/www/html/zend_example/public

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

我只想让 ZF 开发站点启动并运行,同时还有其他站点可用(在相同的基本 URL 下)。

现在,所有请求都重定向(或重写?)到基本 URL (http://MYDOMAIN)。

谢谢!

编辑#1

我为两者编辑了虚拟主机zend_exampleother_site因此每个DocumentRoot都设置为/var/www/html,而不是每个站点的子目录。这使得可以在各自的 URL 中访问这两个站点 - other_site:http://MYDOMAIN/other_site和 zend_example: http://MYDOMAIN/zend_example/public。现在,我相信目录.htaccess中的文件有问题/var/www/html/zend_example/public。我无法访问默认的“Zend” URL,例如http://MYDOMAIN/zend_example/public/index/index应该指向 IndexController。相反,我收到一个404错误。

编辑#2

如果我禁用除zend_example一个之外的所有 vhost,并且 zend_example vhost 已DocumentRoot /var/www/html设置,那么我可以在 下运行 Zend 站点http://MYDOMAIN/zend_example/public,包括特定的默认 Zend 路由,例如http://MYDOMAIN/zend_example/public/index/index. 当我启用另一个虚拟主机时,这会中断,尽管我仍然能够访问 Zend 的主索引页面http://MYDOMAIN/zend_example/public

编辑#3

我最终玩弄了几个小时。由于我的服务器是centos 6.0,因此似乎需要进行一些独特的配置。我最终设置了一个 Debian 6.0 服务器,并且能够正确设置我的虚拟主机,包括 Zend 站点!不过,我仍然想回来解决 centos 上的问题。

4

1 回答 1

1

ServerName在虚拟主机中缺少该选项。此外,如果您不允许followSymlinks在目录声明中使用,您可能会遇到一些困难,请尝试以下操作:

//the ServerName is the name that would follow http:// (http://zend.example/module/controller/action)

<VirtualHost *:80>
    DocumentRoot /var/www/html/zend_example/public
    ServerName zend.example
    SetEnv APPLICATION_ENV "development"
    <Directory /var/www/html/zend_example/public>
        DirectoryIndex index.php
        Options Indexes FollowSymlinks
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>
</VirtualHost>

我不是 *nix 用户,所以我不确定您是否更改了类似于 Windows 主机文件的任何内容,但可能需要进行调查。(看起来您将不得不编辑主机文件,它应该在/etc/hosts添加一行,例如127.0.0.1 zend.examplewhere zend.example = ServerName from your vhost)

PS如果您需要可用的本地主机,您可能必须为本地主机创建一个虚拟主机(如果您的所有虚拟主机都在一个文件中,则作为列表中的第一个)。我知道我必须在 Windows 上执行此操作。

于 2012-04-21T10:59:08.813 回答