在 Apache 下的 url 子文件夹下 运行 ZF 应用程序的正确方法是什么?

What is the correct way to run ZF application under url sub-folder under Apache?

这可能是一个常见问题,但我找不到答案。

我有一个使用 Zend Framework 的 PHP 应用程序。假设我们 运行 my-app 主机下的应用程序和源文件位于本地文件系统中的 /my-path/my-app 下。以下是 Apache 虚拟主机配置:

<VirtualHost *:80>
ServerName my-app
DocumentRoot "/my-path/my-app/public"
<Directory "/my-path/my-app/public">
    AllowOverride All
    Require all granted
</Directory>
</VirtualHost>

public 目录中的 .htaccess 文件包含以下重写规则:

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l
RewriteRule ^.*$ - [NC,L]

RewriteRule ^.*$ index.php [NC,L]

到目前为止,ZF 应用程序的所有标准。

现在,我需要 运行 这个应用程序在 url 子文件夹下(例如 foo),即在 http://my-app/foo/ 下而不是 http://my-app/.

我需要更改什么才能使这项工作正常进行?最佳做法是什么?

假设从应用程序生成带有 base-url 的 URL 不是问题。并且还假设应用程序将重写所有 URL,包括应用程序 css/js 来源的链接。

谢谢!

好的,经过一番尝试后,我找到了简单的解决方案。所需要的只是在 Apache 虚拟主机配置中添加一个别名:

<VirtualHost *:80>
ServerName my-app
DocumentRoot "/my-path/my-app/public"
<Directory "/my-path/my-app/public">
    AllowOverride All
    Require all granted
</Directory>

Alias /foo /my-path/my-app/public

</VirtualHost>