Serving static pages - ViewAction with pretty url enabled gives 404

I tried to solve this myself but I give up. I want to serve static pages using standalone action (The Definitive Guide to Yii 2.0: Rendering Static Pages).

SiteController::actions()


return [

    'page' => [

        'class' => 'yii\web\ViewAction',

    ],

]

urlManager configuration:


'showScriptName' => false,

'enablePrettyUrl' => true,

'rules' => [

    '<alias:about>' => 'site/page/view/<alias>',

],

It looks okay, unfortunately //localhost/about gives 404 (exception ‘yii\base\InvalidRouteException’ with message ‘Unable to resolve the request “site/page/view/about”.’).

I noticed that //localhost/site/page?view=about works fine however I would prefer to skip controller name and ?view=about part. This looks like a bug for me but maybe I’m just doing something wrong.

I’ll be grateful for your help.

try


'about' => 'site/about',

then [i]localhost/yoursite/about should work. This is what i use and it works for me.

make sure in your web root you have your htaccess file with rewrite on


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



[/i]

I think that it works for you because you’re using standard Action, not ViewAction as standalone action, am I right? :) ViewAction needs additional GET parameter (view). My .htaccess file is fine.

Hurray, thanks to your tip I solved the problem. This is correct rule:


'<view:about>' => 'site/page',

glad you got it working