zf创建控制器关于 - 获得404 - 为什么?

时间:2011-04-19 12:12:06

标签: zend-framework

我已完成以下命令:

zf create controller About

因此,zend工具创建了一个控制器,索引操作创建了一个索引视图。

如果我然后去: http://mysite.dev/about/

我收到了404错误。

这是因为在我的AboutController的Index操作中,我没有任何说“看看视图”的内容吗?

如果是这样,我应该采取什么行动,以便显示视图而不是404?

在我的.htaccess文件中,位于:*〜/ public_html / mysite.dev / public / *我有:

Options +FollowSymlinks

SetEnv APPLICATION_ENV development

RewriteEngine On

#hotlinking
RewriteCond %{HTTP_REFERER} !^$ [OR]
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?mysite\.dev [NC,OR]
RewriteCond %{HTTP_REFERER} !^https?://(www\.)?mysite\.something\.com [NC]
RewriteRule \.(jpg|jpeg|png|gif)$ - [NC,F,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

/ etc / apache2 / sites-available 中我有:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName mysite.dev

DocumentRoot /home/user/public_html/mysite.dev/public

<Directory /home/user/public_html/mysite.dev/public>
DirectoryIndex index.php
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
Allow from all
</Directory>

</VirtualHost>

请注意,在此配置中,当我键入命令以创建新的zend项目时,我会正确调用初始Zend页面。

更新

我在.htaccess文件中更改了以下行,现在它正在运行:

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

所以我添加了一个-s标志和一个-l标志,我取消了-d标志和包含!-f标志的行的否定。

具有!-d和!-f的要点是允许访问目录和文件而不重定向目录和文件。所以,如果它是一个文件,如果存在,那么,不要重定向。如果是其他不是文件或目录的东西(即控制器调用),则重定向。

我不明白为什么,通过这种改变,我得到了它的工作。 :(

为什么?

再次感谢。

1 个答案:

答案 0 :(得分:1)

RewriteCond %{REQUEST_FILENAME} **!**-d
RewriteCond %{REQUEST_FILENAME} **!**-f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

erorr在RewriteCond的感叹号中,你说apache,如果请求文件名不是一个目录而不是直接的常规文件,否则转到index.php。

您需要像在新的htaccess文件中那样反转它们:

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
相关问题