简体   繁体   中英

Yii2 CORS requests

I created a simple restful api with yii2, every request worked fine on my local web server. Then I uploaded to shared hosting and half of my requests started to return 404 error. Only GET, POST and OPTIONS requests work as they supposed to.

Url rules:

'class' => \yii\rest\UrlRule::class,
'pluralize' => true,
'controller' => 'todo',
'patterns' => [
    'DELETE {id}'    => 'delete-todo',
    'POST {id}'      => 'create-todo',
    'PUT,PATCH {id}' => 'update-todo',
    'OPTIONS {id}'   => 'options'
],

Let take this rule:

'DELETE {id}' => 'delete-todo',

If I change it to this:

'GET {id}' => 'delete-todo',

and send GET request it will work, but why doesn't it work with DELETE request?

And why does it work properly on my local web server and doesn't on shared hosting?

尝试在您的网址管理器规则中设置'enableStrictParsing'=> false'并设置'pluralize'=> false。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM