2009-08-26 35 views
19

Tôi đang cố gắng tải ứng dụng CakePHP để hoạt động. Đối với điều này, tôi đã thiết lập một thương hiệu cài đặt Debian mới, cập nhật cấu hình và đặt mọi thứ trong/var/www, trong đó có các nội dung sau đây:.htaccess cho cakephp

app 
cake 
.htaccess 
index.php 
vendors 

Các tập tin .htaccess chứa sau:

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

Nếu tôi truy cập vào máy chủ ảo của mình (http://myhost/), tôi thấy trang chính xác. Nhưng nạp thậm chí JavaScript với src="/js/validate.js" thất bại (nó nằm trong /var/www/app/webroot/js/validate.js):

[Wed Aug 26 15:45:12 2009] [error] [client 10.7.10.52] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace. 
[Wed Aug 26 15:45:12 2009] [debug] core.c(3063): [client 10.7.10.52] r->uri = /webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/js/prototype.js 
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/js/prototype.js 
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/js/prototype.js 
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/webroot/webroot/webroot/webroot/js/prototype.js 
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/webroot/webroot/webroot/js/prototype.js 
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/webroot/webroot/js/prototype.js 
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/webroot/js/prototype.js 
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/webroot/js/prototype.js 
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/webroot/js/prototype.js 
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /webroot/js/prototype.js 
[Wed Aug 26 15:45:12 2009] [debug] core.c(3069): [client 10.7.10.52] redirected from r->uri = /js/prototype.js 
[Wed Aug 26 15:45:12 2009] [debug] mod_deflate.c(632): [client 10.7.10.52] Zlib: Compressed 649 to 405 : URL /webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/webroot/js/prototype.js 

Do đó tôi câu hỏi: các .htaccess đúng yêu cầu cho CakePHP là gì?

Rất nhiều người cảm ơn!

+1

Bạn có thư mục nào cho trang gốc trong cấu hình apache của bạn? Nó phải là/var/www/app/webroot - có thể khắc phục được sự cố của bạn. – inkedmn

+0

@inkedmn: cảm ơn bạn, nó sẽ là/var/www - nhưng lỗi là vì tôi chỉ sử dụng một .htaccess, không phải 3, như tôi vừa phát hiện ra. Cảm ơn bạn! – MrG

Trả lời

55

Câu trả lời là có 3 tệp .htaccess khác nhau:

/var/www/app/webroot/.htaccess

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

/var/www/app/.htaccess

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

/var/www/.htaccess

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

Đó là lỗi của tôi, mọi thứ được liệt kê trên CakePHP site. Cảm ơn tất cả mọi người!

+0

Sau khi tìm thấy các logfiles của tôi và googling các lỗi bạn liệt kê ở trên tôi tìm thấy điều này! Cảm ơn rất nhiều! – DirtyBirdNJ

+0

câu trả lời tuyệt vời ......... nó làm việc cho tôi –

+0

cảm ơn bạn ... đã giúp tôi rất nhiều :) – Alex

2

Các .htaccess đúng là mặc định:

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

Bạn cần phải thêm vào trong này "/ etc/apache2/sites-enabled/default":

<Directory /var/www> 
    Options Indexes FollowSymLinks MultiViews 
    AllowOverride All 
    Order allow,deny 
    allow from all 
</Directory> 

nếu phần đã tồn tại thay đổi AllowOverride None để AllowOverride Tất cả

0

Xóa .htaccess khỏi tệp chính có thể giải quyết được sự cố này. Nó làm việc cho tôi (không cần phải loại bỏ từ webroot)

0

Nếu được cho phép bởi nhà cung cấp của bạn, bạn có thể đặt tất cả trong file httpd.conf như sau

<Directory /var/www> 
    Options Indexes FollowSymLinks MultiViews 
    AllowOverride All 
    Order allow,deny 
    allow from all 
    <IfModule mod_rewrite.c> 
     RewriteEngine on 
     RewriteRule ^$ webroot/ [L] 
     RewriteRule (.*) webroot/$1 [L] 
    </IfModule> 
</Directory> 

Và như vậy cho các thư mục khác ...