当子文件夹中的 Codeigniter 应用程序无法访问 rest api 方法

Can't access rest api method when Codeigniter app in sub folder

当我将 Codeigniter 应用程序放入子文件夹时,访问 REST api 方法时遇到问题。我已将 Codeigniter 应用程序放在 rest 文件夹中。然后我尝试调用 http://myapp.dev/rest/api/Workingday/workingDay 并得到 404 未找到,如果我尝试访问 http://myapp.dev/rest/index.php

会出现同样的问题

这是我的文件夹结构

这是我的 extenden rest api 文件夹,所以你可以看到我在控制器中有 api 文件夹,并且会有 public 和 rest API。

这是我的 .htaccess

RewriteEngine on
#RewriteCond  !^(index\.php|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /rest/index.php/ [L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

这是我在 Apache 服务器上的虚拟主机(本地主机开发) 名称虚拟主机 *:80

<VirtualHost *:80>
    ServerName myapp.dev
    ServerAlias *.myapp.dev
    ServerAdmin info@myapp.dev
    DocumentRoot "/Users/user/workspace/myapp" LogLevel debug
    ErrorLog "/Users/user/workspace/myapp/rest/application/logs/myapp.dev-error_log"
    CustomLog "/Users/user/workspace/myapp/rest/application/logs/myapp.dev-access_log" common
</VirtualHost>

这是我的 WorkingDay api 如果您在这里看到任何问题,也许...文件的位置是 /Users//workspace/myapp/rest/application/controllers/api/Workingday.php

class Workingday extends REST_Controller {

    public function workingDays_get($id=NULL){
        if($id != NULL){
            $condition['id_working_day'] = $id;
            $workingDays = $this->Working_days->get($condition);
        }else{
            $workingDays = $this->Working_days->get();
        }
        if($workingDays){
            $this->response($workingDays, REST_Controller::HTTP_OK);
        }else{
            $this->response([
                'status' => FALSE,
                'message' => 'No time of day data were found'
            ], REST_Controller::HTTP_NOT_FOUND);
        }
    }
}

我认为问题出在 .htaccess 文件中,但我不知道如何正确配置它。如何正确配置我需要的一切以便进一步开发我的应用程序?

****更新**

我认为访问 http://myapp.dev/rest/index.php 是有效的,因为它显示了 Codeigniters 404 页面(只有 none 初始控制器已初始化)

访问日志:

127.0.0.1 - - [09/Dec/2017:17:58:00 +0100] "GET /rest/ HTTP/1.1" 404 1130
127.0.0.1 - - [09/Dec/2017:18:00:54 +0100] "GET /rest/index.php HTTP/1.1" 404 1130

访问时 http://myapp.dev/rest/api/Workingday/workingDay 显示浏览器 404 页面

访问日志

127.0.0.1 - - [09/Dec/2017:17:53:18 +0100] "GET /rest/api/Workingday/workingDay HTTP/1.1" 404 228

我不知道我到底做了什么,但我的应用程序是如何突然开始工作的……

这是我的 .htaccess 文件

RewriteEngine on
#RewriteCond  !^(index\.php|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /rest/index.php/ [L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

这是我的虚拟主机配置文件(我认为这解决了问题)

<VirtualHost *:80>
    ServerName myApp.dev
    ServerAlias *.myApp.dev
    ServerAdmin info@myApp.dev
    DocumentRoot "/Users/<user>/workspace/myApp"
    LogLevel debug
    ErrorLog "/Users/<user>/workspace/myApp/rest/application/logs/myApp.dev-error_log"
    CustomLog "/Users/<user>/workspace/myApp/rest/application/logs/myApp.dev-access_log" common
    <Directory   "/Users/<user>/workspace/myApp">
        Options Indexes FollowSymLinks
        AllowOverride All
        Allow from all
    </Directory> 
</VirtualHost>