从具有 .htaccess 规则的文件夹中运行 Zend Framework
问候。基本上,我试图从文件夹中运行 Zend Framework 应用程序(实际上是多个应用程序)——但不指定公共目录。我知道这听起来很肮脏,但我有我的理由,所以这超出了我的问题范围。
例如,这可能是我的 ZF“安装”之一:
http://www.myurl.com/project1/
(其他可能位于 /project2/ 等)
我正在使用标准 ZF 目录结构。我还熟悉在项目文件夹中放置 .htaccess 以将流量重定向到 /public/ 的各种方法,这通常用于使用 Zend Framework 的共享托管环境 - 问题是,当您的项目根目录不是基本 URL,它似乎不起作用。
具体来说,如果我将以下 .htaccess 文件放在 /project1/ 中
RewriteEngine 开启
RewriteRule ^(.*)$ public/$0 [L]
我收到一个 ZF 错误页面,指出:
指定的控制器无效(项目1)
因此似乎认为该文件夹名称是控制器。
如果我使用此处解释的更冗长的解决方案,我也会遇到同样的问题: http://www.alberton.info/zend_framework_mod_rewrite_shared_hosting.html
(显然,我将路径替换为包含“我的”路径的路径,即/project1/)
非常感谢任何帮助!
Greetings. Basically, I'm trying to run a Zend Framework application (multiple of them, actually) from within folders -- but without specifying the public directory. I know this sounds dirty but I have my reasons so it's outside the scope of my question.
For example, this may be one of my ZF "installs":
http://www.myurl.com/project1/
(Others may be at /project2/, etc.)
I'm using the standard ZF directory structure. I'm also familiar with the various methods of placing an .htaccess in the project folder to redirect traffic to /public/ that is often used for shared hosting environments with Zend Framework -- the problem is that when your project root isn't the base URL, it doesn't seem to work.
Specifically, if I place the following .htaccess file in /project1/
RewriteEngine On
RewriteRule ^(.*)$ public/$0 [L]
I get a ZF error page stating:
Invalid controller specified (project1)
So it seems to think that the folder name is a controller.
I get the same problem if I use the more lengthy solution explained here:
http://www.alberton.info/zend_framework_mod_rewrite_shared_hosting.html
(Obviously, I replace the paths with paths that contain "my" path, ie. /project1/)
Any help is much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,我之前的回答很愚蠢。尝试不同的策略。
对 这篇文章 的评论指出了这个问题,但是它可以通过在应用程序的前端控制器上设置
baseUrl
来处理。我将向
application/configs/application.ini
添加一个条目(可能针对每个环境),然后在Bootstrap
中设置它。这应该允许路由忽略/project1/
前缀并专注于 url 的其余部分。更新
我会设置一个类似
application.ini
的密钥,例如:如果这因每个环境而异,那么您可以为每个环境添加一个条目:
然后在
application/Bootstrap.php
,添加一个方法,例如:That oughtta do it。
OK, my previous answer was boneheaded. Trying a different tack.
A comment on this post notes this problem but that it can be handled by setting the
baseUrl
on the app's front controller.I'd add an entry to
application/configs/application.ini
(probably per environment) and then set it inBootstrap
. That should allow the routing to ignore the/project1/
prefix and focus on the rest of the url.Update
I would set a key like
application.ini
, something like:If this varies on a per-environment basis, then you could add an entry per-environment:
Then in
application/Bootstrap.php
, add a method like:That oughtta do it.
根据 David 的回答,如果您不需要重写 /public 中的资源,请执行以下操作
假设您在 url domain.com/yourapplication 有一个项目,
在 /application/configs/application.ini 中创建 /.htaccess ,
添加
到 /application /Bootstrap.php add
现在,当您在浏览器中访问domain.com/yourapplication时,htaccess会将所有不是有效文件的请求重定向到domain.com/yourapplication/public,并将前端控制器设置为yourapplication。
Following on from David's answer, if you need to NOT rewrite resources in /public do the following
Say you have a project at url domain.com/yourapplication
create /.htaccess like this
in /application/configs/application.ini add
in /application/Bootstrap.php add
Now when you go to domain.com/yourapplication in a browser, htaccess will redirect all requests that aren't valid files into domain.com/yourapplication/public and set your front controller to yourapplication.