Home > Software design >  Enabling pretty URLs / urlManager completely breaks Yii 2 application runnikg as a REST micro-framew
Enabling pretty URLs / urlManager completely breaks Yii 2 application runnikg as a REST micro-framew

Time:06-04

tl;dr My Yii 2 app, running enter image description here

As suggested in enter image description here

nor pretty URLs:

enter image description here

It even fails to serve the default controller and action -- site/index.

What am I missing?

It seems that I have everything that I need. Following the guide I have:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

What else must I do in order to make the whole thing work or what am I missing here? Thanks!

CodePudding user response:

Remove this line:

'enableStrictParsing' => true,

CodePudding user response:

This question comes from an misunderstanding. I wasn't aware that when pretty URLs are enabled then yii\rest\UrlRule::$pluralize is set to true by default. Meaning that the request must be:

http://localhost/micro-app/posts

(plural controller name; notice "s" at the end)

Not:

http://localhost/micro-app/post

(singular controller name)

It is also completely normal that when pretty URLs are enabled then regular URLs doesn't work anymore. That's the reason for getting 404 File Not Found on http://localhost/micro-app/index.php?r=post URL when pretty URLs are enabled.

  • Related