ZF2 Apache 安装在 VPS 上而不创建虚拟主机

ZF2 Apache install on VPS witout creating Virtual Host

我想在不支持虚拟主机的 VPS 服务器上安装我的 ZF2 应用程序。我正在使用基于 ZendApplicationSkeleton 的简单应用程序。

我使用默认 .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 ^.*$ - [NC,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, 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}:: ^(/.+)(.+)::$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]

我在 SO 中找到的所有解决方案都不适合我。它们可能适合 ZF1,但不适合 ZF2:

Link 1

Link 2

Link 3

Link 4

我的应用程序位于名为 /var/www/html/testapp 的文件夹中。

一旦我在浏览器上输入localhost/testapp/public,主页就会加载。如果我键入 localhost/testapp/module,我的模块也会加载,但导航不起作用。

即:在主页面上,我创建了一个按钮,如:

<a href="/module/index">Go To Module</a>

但如果我点击它,我会导航到 localhost/login/index,显示 Not Found,而不是正确的 module/index.phtml 页面。

对此表示感谢。

您的问题与服务器配置无关。由于您的应用位于子文件夹中,因此 link 是错误的。它需要类似于

<a href="/testapp/public/module/index">Go To Module</a>

让它工作。但是,public/ 永远不应出现在您的网址中。通过这种方式设置,您允许用户查看您应用的网络根目录之外的文件,这是一个潜在的安全风险(并导致难看的 URL)。

解决方案是为您的 ZF2 应用程序设置一个单独的虚拟主机,它有一个指向应用程序 public 文件夹的 DOCUMENT ROOT。如果您对此有疑问,post 那就是您的问题;或者,如果您能解释为什么这是不可能的,也许我们可以提供进一步的建议。