【发布时间】:2016-06-11 21:22:30
【问题描述】:
我想在不支持虚拟主机的 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}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
我在 SO 中找到的所有解决方案都不适合我。它们可能适合 ZF1,但不适合 ZF2:
我的应用程序位于名为/var/www/html/testapp 的文件夹中。
我在浏览器上输入localhost/testapp/public 后,主页就会加载。如果我输入localhost/testapp/module,我的模块也会被加载,但导航不起作用。
即:在主页中,我创建了一个按钮,例如:
<a href="/module/index">Go To Module</a>
但如果我点击它,我会导航到显示Not Found 的localhost/login/index,而不是正确的module/index.phtml 页面。
帮助感谢。
【问题讨论】:
-
您使用什么托管服务?我简直不敢相信不可能以某种方式设置您要服务的文件夹?
-
看起来你有某种登录/身份验证检查,当链接 /module/index 被访问时重定向到 localhost/login/index。检查您的登录名/身份验证器,并确保在您不需要登录时禁用重定向(开发目的)
-
另外,对于 ZF2 应用程序,public 文件夹应该是您的 webapp 的根目录。因此,您需要将 VHOST 配置为使用 /var/www/html/testapp/public 作为 DocumentRoot。此外,由于您的应用程序位于 /var/www/html 中,默认的 Apache 配置也可能会尝试直接提供文件,这可能会导致 url 与您的任何 ZF2 路由定义都不匹配。最好将您的应用程序移到 /var/www/html 目录之外,以便在您的服务器配置发生问题时不会意外访问所有私有配置/文件
标签: php apache .htaccess zend-framework2