D
D
Doctor Bi2018-08-14 12:30:25
Yii
Doctor Bi, 2018-08-14 12:30:25

How to enable pretty url yii2?

Hello everyone ,
I'm doing a rest api on the yii2-basic template , the task was to upload what was done to the hosting
, it's worth making a reservation that openserver is installed on the LAN and the local domain "looks" in the web
folder and pretty url work,
5b729d61bf24c242966167.png
but on the hosting the site gives an error exception 'yii\web\ NotFoundHttpException' with message 'Page not found.' in /api/vendor/yiisoft/yii2/web/Request.php:284
5b729e40b7484826349761.png
If the url manager is turned off, then everything on the hosting works, so the problem may be in the
config manager looks like this:

$config = [
    'id' => 'api-artpix',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],

    'components' => [
        'request' => [
            'parsers' => [
                'application/json' => 'yii\web\JsonParser',
            ]
        ],
        'response' => [
            'formatters' => [
                'json' => [
                    'class' => 'yii\web\JsonResponseFormatter',
                    'prettyPrint' => YII_DEBUG,
                    'encodeOptions' => JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE,
                ],
            ],
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => false,
            'enableSession' => false,
        ],

        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            // send all mails to a file by default. You have to set
            // 'useFileTransport' to false and configure a transport
            // for the mailer to send real emails.
            'useFileTransport' => true,
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'db' => $db,

        'urlManager' => [
            'enablePrettyUrl' => true,
            'enableStrictParsing' => true,
            'showScriptName' => false,
            'rules' => [
                'create' => 'order/create',
                '<controller:\w+>/<action:\w+>/' => '<controller>/<action>'
            ],
        ],

    ],
    'params' => $params,
];

.htaccess at the root
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

RewriteCond %{REQUEST_URI} !^/(web)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) /web/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /web/index.php

.htaccess to web
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

I tried to change it so that the domain on the hosting also "looks" in the web folder , but then the server starts to issue a 500 error

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Doctor Bi, 2018-08-14
@scanerrr

Found solution in web
folder changed htaccess to

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

And everything worked.
Thank you Maxim Timofeev for pointing me in the right direction

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question