提问者:小点点

当Codeigniter应用程序位于子文件夹中时,无法访问rest api方法


我有问题访问我的REST api方法,当我把我的Codeigniter应用程序在子文件夹。我已经把Codeigniter应用程序内Rest文件夹。然后我尝试调用http://myapp.dev/rest/api/Workingday/workingDay和我得到404找不到,同样的问题出现,如果我尝试访问http://myapp.dev/rest/index.php

这是我的文件夹结构

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

这是我的. htaccess

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

这是我在Apache服务器上的vhost(localhost开发)名称virtualhost*: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>

这是我的工作日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页面(没有初始化初始控制器)

访问日志:

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

共1个答案

匿名用户

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

这是我的. htaccess文件

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

这是我的vhost会议(我想这解决了问题)

<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>