将cakePHP 2.3.4 REST API从开发转移到生产404错误

时间:2013-05-13 03:46:24

标签: cakephp mod-rewrite

我正在研究一个简单的REST API,它正在我的开发系统(Mac OSX,Zend Studio,Zend Server CE - http://localhost:10088/apitest/)中使用.htaccess文件中的RewriteBase(见下文)。我修改.htaccess文件以使用我创建的Apache 2.2虚拟主机(https://api.domain.com/),我收到404错误。唯一的变化是.htaccess中的(1)RewriteBase行,网址中的https:access。

错误回复:

<response>
    <code>404</code>
    <url>/v1/flightlogs/9230.xml</url>
    <name>
        Controller class FlightlogsController could not be found.
    </name>
</response>

**以下评论的RewriteBase行正在开发中。 **

/v1/.htaccess:

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

/v1/app/.htaccess:

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

/v1/app/webroot/.htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    #RewriteBase /apitest/v1/app/webroot/
    RewriteBase /v1/app/webroot/
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

Apache重写日志:

[api.domain.com] (2) [perdir /home/level/public_html/api/v1/] trying to replace prefix /home/level/public_html/api/v1/ with /v1/
[api.domain.com] (2) init rewrite engine with requested uri /v1/app/webroot/flightlogs/9230.xml
[api.domain.com] (1) pass through /v1/app/webroot/flightlogs/9230.xml
[api.domain.com] (2) [perdir /home/level/public_html/api/v1/app/webroot/] rewrite 'flightlogs/9230.xml' -> 'index.php'
[api.domain.com] (2) [perdir /home/level/public_html/api/v1/app/webroot/] trying to replace prefix /home/level/public_html/api/v1/app/webroot/ with /v1/app/webroot/
[api.domain.com] (1) [perdir /home/level/public_html/api/v1/app/webroot/] internal redirect with /v1/app/webroot/index.php [INTERNAL REDIRECT]
[api.domain.com] (2) init rewrite engine with requested uri /v1/app/webroot/index.php
[api.domain.com] (1) pass through /v1/app/webroot/index.php
[api.domain.com] (1) [perdir /home/level/public_html/api/v1/app/webroot/] pass through /home/level/public_html/api/v1/app/webroot/index.php

我可以统计最终路径:/home/level/public_html/api/v1/app/webroot/index.php

[root@l4 httpd]# stat /home/level/public_html/api/v1/app/webroot/index.php
  File: `/home/level/public_html/api/v1/app/webroot/index.php'
  Size: 3189        Blocks: 8          IO Block: 4096   regular file
Device: fd00h/64768d    Inode: 2620573     Links: 1
Access: (0644/-rw-r--r--)  Uid: (  501/   level)   Gid: (  506/tracking)

Apache 2虚拟主机:

<VirtualHost *:443>
    ServerAdmin webmaster@airlinecert.com
    DocumentRoot /home/level/public_html/api
    ServerName api.levelflight.com:443
    ErrorLog logs/api_ssl_error_log
    TransferLog logs/api_ssl_access_log
    LogLevel warn
    RewriteEngine On
    RewriteOptions Inherit
    RewriteLog logs/api_rewritelog_log
    RewriteLogLevel 2

    <Directory "/home/level/public_html/api">
        Options -Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
    </Directory>


</VirtualHost>

Apache访问日志:

173.60.78.93 - api_username [13/May/2013:06:20:56 -0700] "GET /v1/flightlogs/9230.xml HTTP/1.1" 404 181

Apache错误日志:

[Mon May 13 06:20:56 2013] [error] [client x.x.x.x] core.php:SetDebug:Server_Name: api.levelflight.com debug:2

网址差异是:

发展:http://localhost:10088/apitest/v1/flightlogs/9230.xml

制作:https://api.domain.com/v1/flightlogs/9230.xml

有些东西应该打在我的脸上,我无法看到它。有什么想法吗?

/v1/app/tmp/logs/error.log

2013-05-13 06:05:38 Error: [MissingControllerException] Controller class FlightlogsController could not be found.
Exception Attributes: array (
  'class' => 'FlightlogsController',
  'plugin' => NULL,
)
Request URL: /v1/flightlogs/9230.xml
Stack Trace:
#0 /home/level/public_html/api/v1/app/webroot/index.php(109): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))
#1 {main}

1 个答案:

答案 0 :(得分:1)

看起来像是一个区分大小写的问题。 Mac OSX(不区分大小写)和Red Hat(区分大小写)之间的区别。飞行日志控制器和模型不一致:FlightLogsFlightlogs都被使用。

我找到Flightlogs的所有实例,并将其更改为FlightLogs,错误似乎已消失。

...... l和L之间的区别......