我想在不支持虚拟主机的情况下将我的ZF2应用程序安装在VPS服务器上。我正在使用基于ZendApplicationSkeleton的简单应用程序。ZF2安装在VPS上的Apache无需创建虚拟主机
I'm使用默认.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]
所有解决方案中从来就发现,因此不会为我工作。他们可能适合ZF1,但不ZF2:
我的应用程序是一个名为/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
页面。
帮助赞赏与此。
您使用哪种托管服务?我几乎不相信有没有可能以某种方式设置你想要服务的文件夹? – Wilt
看起来您有某种登录/身份验证检查,当链接/模块/索引访问时,它会重定向到localhost/login/index。检查您的登录名/身份验证器,并确保如果您不需要登录(dev目的),重定向被禁用 – xangxiong
此外,对于ZF2应用程序,公用文件夹应该是您的web应用程序的根目录。所以你需要配置你的VHOST使用/ var/www/html/testapp/public作为DocumentRoot。此外,由于您的应用程序位于/ var/www/html中,因此默认的Apache配置可能也会尝试直接提供这些文件,这可能会导致网址与您的任何ZF2路由定义不匹配。最好将你的应用移动到/ var/www/html目录之外,这样如果你的服务器配置发生什么事情,所有私人配置/文件都不能被意外访问 – xangxiong