YII2 RESTFUL 404 -


i search less infomesion while doing

  • my config (rest.php)

    <?php $params = require(__dir__ . '/params.php'); $config = [     'id' => 'rest-api',     'basepath' => dirname(__dir__),     'language' => 'zh-cn',     'controllernamespace' => 'rest\controllers',     'bootstrap' => ['log'],     'modules' => [        'v1' => [           'class' => 'rest\versions\v1\module',     ], ], 'components' => [     'errorhandler' => [        'erroraction' => 'site/index',    ],     'urlmanager' => [         'enableprettyurl' => true,         'enablestrictparsing' => true,         'showscriptname' => false,         'rules' => [             [                 'class' => 'yii\rest\urlrule',                 'controller' => [                     'v1/product',                 ],             ]         ],     ],     'log' => [         'tracelevel' => yii_debug ? 3 : 0,         'targets' => [             [                 'class' => 'yii\log\filetarget',                 'levels' => ['error', 'warning'],             ],         ],     ],     'db' => require(__dir__ . '/db.php'),     'request' => [         'parsers' => [             'application/json' => 'yii\web\jsonparser',         ]     ], ], 'params' => $params,  ];  return $config; 
  • my module.php

     <?php  namespace rest\versions\v1;   use yii;  use yii\base\module;  class module extends module  {   public $controllernamespace = 'rest\versions\v1\controllers';    public function init()   {     parent::init();   }  } 
  • my .htaccess file,it's code this.

      options +followsymlinks    indexignore */*     rewriteengine on     # if directory or file exists, use directly    rewritecond %{request_filename} !-f    rewritecond %{request_filename} !-d     # otherwise forward index.php    rewriterule . index.php 

    my product controller

      <?php   namespace rest\versions\v1\controllers;    use yii;   use yii\rest\activecontroller;    class productcontroller extends activecontroller   {      public $modelclass = 'rest\versions\v1\models\product';       public function actionindex()      {          return 'haha';      }    } 

i still 404

http://rest.mcolor.com/v1/products

i got info

         404 not found           nginx/1.8.1 

plz me.

it looks using .htaccess file rewrites, @ server installed nginx web server(you can see @ 404 response body.)

so can use example of nginx config tutorial , change domains, path, etc:

server { charset utf-8; client_max_body_size 128m;  listen 80; ## listen ipv4 #listen [::]:80 default_server ipv6only=on; ## listen ipv6  server_name mysite.local; root        /path/to/basic/web; index       index.php;  access_log  /path/to/basic/log/access.log; error_log   /path/to/basic/log/error.log;  location / {     # redirect isn't real file index.php     try_files $uri $uri/ /index.php?$args; }  # uncomment avoid processing of calls non-existing static files yii #location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ { #    try_files $uri =404; #} #error_page 404 /404.html;  location ~ \.php$ {     include fastcgi_params;     fastcgi_param script_filename $document_root/$fastcgi_script_name;     fastcgi_pass   127.0.0.1:9000;     #fastcgi_pass unix:/var/run/php5-fpm.sock;     try_files $uri =404; }  location ~ /\.(ht|svn|git) {     deny all; } 

}


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -