【问题标题】:CakePHP controller , Url not found on serverCakePHP 控制器,在服务器上找不到 URL
【发布时间】:2018-01-29 14:42:10
【问题描述】:

我在 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
}
 }
}

并且我在 POSTMAN 上成功测试了“http://localhost/dentech/api/ecall_request”,但是当我将其上传到服务器 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]

【问题讨论】:

  • 在浏览器中输入 URL 时可以访问控制器方法吗?由于您似乎正在尝试构建 API,因此我认为您正在发出跨源请求 (CORS)。您可能需要添加 header('Access-Control-Allow-Origin: *');为了允许 CORS 请求。
  • 否,无法在浏览器中访问
  • 是 @user2672106 我正在尝试构建一个 API 以通过 cronjob 访问
  • 该链接无法通过此dentech.com/api/ecall_request 获得,在检查域后,它应该可以在没有“https”的情况下访问dentech.com/api/ecall_request 并且仍然找不到 URL。您是否正在更改托管服务提供商?或者您是否已经上传了 cakephp 文件并覆盖了服务器中的现有文件?如果您已经上传了它,那么问题还没有指向新服务器.....该网站的扩展名为 .aspx dentech.com/home.aspx
  • @SuryaprakashPatel:您的 APIController 是大写字母,而您复制的 URL 不是。也许这就是问题所在。如果您的本地开发系统在 Windows 上运行(不区分大小写)而您的服务器在 Linux 上运行(区分大小写),这可能就是问题所在。

标签: cakephp cakephp-2.9


【解决方案1】:

从 cmets 更新:404 错误的原因是 URL 中的控制器名称必须为大写字符。而不是

https://dentech.com/api/ecall_request

你需要使用

https://dentech.com/API/ecall_request

它在本地主机上工作但在服务器上不工作的事实是操作系统的差异。 Windows(通常在本地使用)不区分大小写,而 Linux(通常是服务器操作系统)区分大小写。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-15
    • 2012-11-06
    • 2012-08-16
    相关资源
    最近更新 更多