在子目录中运行 ZendFramework 项目
我有一个 ZendFramework 项目,我想在子目录中运行。
目前,我的文档根目录位于 /var/www ,项目位于 /var/www/project ,其中包含各种文件夹(controllers、< em>public 等)都在 project 目录中。
我正在尝试将来自 http://webserver/project/* 的所有请求传递给 < /var/www/project/public/index.php 文件。但是,尝试在/var/www/project/.htaccess中使用以下代码来传递所有请求是行不通的:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /project/public/index.php [NC,L]
/var/www/project/.htaccess中还有一个.htaccess
文件>/var/www/project/public 包含完全相同的代码,但在加载 /project URL 时,我只会看到项目内容的目录索引。
I have a ZendFramework project that I would like to run inside a subdirectory.
Currently my document root is at /var/www and the project is at /var/www/project with the various folders (controllers, public, etc.) all within the project directory.
I am trying to make it so that all requests from http://webserver/project/* are being passed to the /var/www/project/public/index.php file. However, trying to use the following code in /var/www/project/.htaccess to pass all requests does not work:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /project/public/index.php [NC,L]
There is also an .htaccess
file in /var/www/project/public that contains exactly the same code, but when loading the /project URL I am just presented with a directory index of the project contents.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我会将项目完全独立于文档根目录存储,例如
/home/user/projects/project
。然后,只需将
/var/www/project
符号链接到/home/user/projects/project/public
。如果您对任何静态资源链接(JavaScript、图像、CSS 等)使用 BaseUrl 视图助手,它应该可以正常工作。
编辑:另一个建议是将公共目录与应用程序的其余部分分开。
例如,假设您的项目位于
/home/user/projects/project
中,请将public
目录的内容移动到/var/www/project
code> 并使用以下内容编辑index.php
I'd store the project completely separate to the document root, for example
/home/user/projects/project
.Then, simply symlink
/var/www/project
to/home/user/projects/project/public
.Provided you use the BaseUrl view helper for any static asset links (JavaScript, images, CSS, etc), it should work just fine.
Edit: Another suggestion is to separate your public directory from the rest of the application.
For example, say your project is in
/home/user/projects/project
, move the contents of yourpublic
directory to/var/www/project
and editindex.php
with the following我知道这是一个老问题,提问者早已找到了他的问题,但我刚刚遇到了它。这是我发现最简单的解决方案,希望到达这里的其他人都能看到这一点。
在您的 VirtualHost 文件中,只需在您的标签上添加一个别名即可创建一个像这样的 VirtualHost 文件
编辑:刚刚发现您必须编辑您的 .htaccess (在 public 目录中)以包含此行(继续上面的例子):
这是 Phil 的一个非常好的答案,与我的类似,但他完全删除了他的 .htaccess 文件,而是将规则放入 VirtualHosts 文件中。 https://stackoverflow.com/a/7563414/1031714
I know this is an old question and the asker has long since figured out his problem but I just ran into it. This is the solution I found that worked the simplest and hopefully anybody else that arrives here will see this.
In your VirtualHost file simply add an Alias right about your tag to create a VirtualHost file like this
Edit: Just figured out you will have to edit your .htaccess (in the public directory) to include this line (going with the above example):
Here's a pretty good answer by Phil that's similar to mine but he removes his .htaccess files completely and instead puts the rules inside the VirtualHosts file. https://stackoverflow.com/a/7563414/1031714
删除第一个 RewriteRule:它表示所有地址都重写为空(
-
)并停止([L]
标志)。编辑:这应该适合您的需求
这会将任何对project/不包含public/的请求重写为project/public/。
下一个将对不存在的文件或目录的任何调用重定向到同一目录中的index.php。
Remove the first RewriteRule: it is saying for all addresses rewrite to nothing (
-
) and stop ([L]
flag).Edit: This should fits your needs
This rewrites any request to project/ not containing public/ to project/public/.
The next one redirects any call to non existing file or dir to index.php in the same directory.