[英]Zend Framework controller load failure puzzle
我有一个.htaccess
文件,看起来像这样:
SetEnv APPLICATION_ENV development
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
如果我浏览到要测试的网站,例如http://www.example.com/ ,则索引页面将正确加载。
这是一个Zend Framework应用程序,因此它应该将内容路由到我的控制器,因为如果我转到http://www.example.com/index/index或http://www.example.com/ ,它将正确地进行路由index ,分别指定控制器+动作和仅控制器。
如果我执行http://www.example.com/index/test之类的操作 ,则该方法也适用,在该操作上我已在索引控制器上定义了另一个名为test的操作。
但是,如果我创建一个TestController.php
文件,并尝试转到http://example.com/test/ ,则Apache返回:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /path/to/website/root/public/index.php was not found on this server.</p>
<hr>
<address>Apache/2.2.8 (Ubuntu) DAV/2 SVN/1.4.6 PHP/5.2.4-2ubuntu5.10 with Suhosin-Patch Phusion_Passenger/2.0.3 mod_perl/2.0.3 Perl/v5.8.8 Server at www.example.com Port 80</address>
</body></html>
有人可以看到我在这里搞砸了吗?
比利3
编辑:我的站点的配置类似于:
Alias /MySiteRoot/ "/usr/local/vsites/something/www/"
<Directory /usr/local/vsites/something/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
当mod_rewrite无法正常工作时,我通常会遇到此问题。
如果已经启用了mod_rewrite,请在/etc/apache2/sites-available/yoursite.com配置文件中,将AllowOverride设置为All。
因此,如果我没看错,则路由工作正常,但是当您仅在url中指定控制器时,路由却无法正常工作。
因此,您具有以下内容:
class TestController extends Zend_Controller_Action
{
//do you have an index action???
public function indexAction()
{
}
}
事实证明,如果您的站点不是域的根,则必须添加RewriteBase指令才能正确格式化内容。 我仍然不知道为什么它事先报告了正确的文件,但现在似乎可以使用了。
感谢,并有一个愉快的一天 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.