我在CakePhp-2.9中编写了一个名为API的控制器,用于访问外部。 控制器代码:
class APIController extends AppController
{
var $name = 'API';
var $cache_dir = 'img/cache';
var $cache_width = 400;
public $msgs = array();
public function beforeFilter()
{
parent::beforeFilter();
$this->Auth->allow('ecall_request','ecall_callback','testlog','ecall_request_test','ecall_callback_test');
}
public function ecall_request()
{
Cache::write("test_request".time(),$this->request->data);
if($this->request->is('post'))
{
// my code here
}
}
}
我测试了#34; http://localhost/dentech/api/ecall_request"在POSTMAN上成功,但是当我在https://dentech.com/api/ecall_request的服务器上传它时,它无法访问并发出404错误。
htaccess代码是:
<IfModule mod_rewrite.c>
RewriteEngine on
# Uncomment if you have a .well-known directory in the root folder, e.g. for the Let's Encrypt challenge
# https://tools.ietf.org/html/rfc5785
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#RewriteRule ^(\.well-known/.*)$ $1 [L]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
答案 0 :(得分:0)
从评论更新:404错误的原因是URL中的控制器名称必须是大写字符。而不是
您需要使用
它在localhost上运行但在服务器上运行的事实是操作系统的不同之处。 Windows(通常在本地使用)不区分大小写,而Linux(通常是服务器操作系统)区分大小写。