2010-01-16 22 views
0

我有一個.htaccess文件看起來像這樣:Zend框架控制器加載失敗之謎

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框架應用程序,因此它應該路由的事情了我的控制器,因爲它不正確,如果我去http://www.example.com/index/indexhttp://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> 

有人能看到我在這裏搞砸了?

Billy3

編輯:我的網站的配置看起來像:

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> 

回答

0

事實證明,如果你的網站是不是域的根,你必須爲了增加RewriteBase指令,以便正確格式化的東西。我仍然不知道爲什麼事先報告了正確的文件,但似乎現在起作用。

感謝,並有一個愉快的一天:)

1

時的mod_rewrite不工作,我通常遇到了這個問題。

如果您已啓用mod_rewrite,請在/etc/apache2/sites-available/yoursite.com配置文件中檢查AllowOverride是否設置爲全部。

+0

如果mod_rewrite並沒有,爲什麼'HTTP:// www.example.com /索引/ index'正常工作?爲什麼'/ path/to/website/root/public/index.php'存在,儘管Apache抱怨相反? – 2010-01-17 02:16:17

+0

編輯我的問題 - AllowOverride所有列出:( – 2010-01-17 02:27:30

+0

有趣的 - 如果我關閉'.htaccess'中的'MultiViews'選項,那麼甚至沒有'http:// www.example.com/index/index'工作正常。我懷疑我的index.php在這一點上有一些權限問題。 – 2010-01-17 03:19:30

0

所以,如果我正確讀取這個,路由工作正常,但不是當你只指定在url中的控制器。

所以,你有以下幾點:

class TestController extends Zend_Controller_Action 
{ 

    //do you have an index action??? 
    public function indexAction() 
    { 

    } 

} 
+0

是的,請注意,錯誤信息是由Apache生成的 - 而不是Zend Framework。 – 2010-01-19 05:11:21