-1
我搜索此得到較少infomesion而我做YII2 RESTFUL 404
我的配置(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;
我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(); } }
我的.htaccess文件,它是這樣的代碼。
Options +FollowSymLinks IndexIgnore */* RewriteEngine on # if a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # otherwise forward it to index.php RewriteRule . index.php
我的產品控制器
<?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'; } }
我仍然得到404
http://rest.mcolor.com/v1/products
我得到的信息
404 Not Found
nginx/1.8.1
plz幫助我。
謝謝@ s_mart – user6249525