2012-11-02 35 views
0

我做了所有的設置,不使用mod_rewrite Apache 2.2和CakePHP。Cakephp 2.2沒有mod_rewrite重定向錯誤

Apache2正在運行,Cake似乎也在運行。如果我去http://127.0.0.1/cake/index.php,所有綠色標籤(使用PostgreSQL 9.1)。我按照教程create the blog project創建了控制器文件/var/www/cake/app/Controller/PostsController.php(也有CakeControllerAppControllerPagesController文件)。

在模型目錄中,我得到了Post.php和AppModel,如教程所述。在View文件夾中,我創建了Posts文件夾和文件index.ctp和view.ctp。

當我輸入像http://127.0.0.1/cake/index.php?url=/posts/這樣的網址時,它會轉到Cake主文件夾的index.php。它重定向到那裏!如果我將URL更改爲例如http://127.0.0.1/cake/index.php?url=/posts/view/1(如教程)一樣的東西。這張照片出了什麼問題?

我的環境是Debian 6.0-6 64bits。 Apache2.2(與SO一起安裝),CakePHP 2.2.3和PHP 5.2.8(或更高版本)。

回答

1

您確定mod_rewrite已啓用並重寫嗎? 您可以發佈.htaccess文件的內容 - 頂級目錄中的內容(即htdocs)和app/webroot目錄中的內容?您的頂級目錄是其中包含applib的目錄。 我懷疑你的RewriteRule在兩者中都是錯誤的。無論如何,如果你沒有改變這些文件,它肯定會出錯。 :)您不應該更改中間的.htaccess文件 - app中的文件。

這已經回答了here和CakeBook解釋它here。但我個人使用有點不同設置:

/var/www/test.cake.lan/htdocs/.htaccess

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteRule ^$ /app/webroot/ [L] 
    RewriteRule (.*) /app/webroot/$1 [L] 
</IfModule> 

/var/www/test.cake.lan /htdocs/app/.htaccess

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteRule ^$ webroot/ [L] 
    RewriteRule (.*) webroot/$1 [L] 
</IfModule> 

/var/www/test.cake.lan/htdocs/app/webroot/.htaccess

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^(.*)$ /app/webroot/index.php?url=$1 [QSA,L] 
</IfModule> 
+0

Dude,ty年老的VM回答,但我想你錯過了......正如我說的我的目標是不使用mod_rewrite。因此,如解釋我取消註釋一行和刪除所有.htaccesss(實際上我重命名所有,但),我用網址的提到b4。 –

+1

無論如何,我指出了答案...... Yr鏈接讓我學到了更多。 –