S
S
Sergey Beloventsev2016-03-03 20:57:22
Yii
Sergey Beloventsev, 2016-03-03 20:57:22

Why is there an error when using urlManager?

I use the advanced template, but for some reason, if I connect urlManager, then 1 stops working, or rather, not even the urlManager itself, but showScriptName => false
, and in general, some styles are completely disabled, I connect like this

'urlManager' => [
                'class' => 'yii\web\UrlManager',
                'enablePrettyUrl' => true,
                /*'showScriptName' => false,*/
            ],

here is htaccess
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on

# Если запрос начинается с /admin, то заменяем на /backend/web/
RewriteCond %{REQUEST_URI} ^/admin
RewriteRule ^admin\/?(.*) /backend/web/$1

# Если запрос начинается с /api, то заменяем на /rest/web/
RewriteCond %{REQUEST_URI} ^/api
RewriteRule ^api\/?(.*) /rest/web/$1

# Добавляем другой запрос /frontend/web/$1
RewriteCond %{REQUEST_URI} !^/(frontend/web|backend/web|rest/web|admin|api)
RewriteRule (.*) /frontend/web/$1

# Если frontend запрос
RewriteCond %{REQUEST_URI} ^/frontend/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /frontend/web/index.php

# Если api запрос
RewriteCond %{REQUEST_URI} ^/rest/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /rest/web/index.php

# Если backend запрос
RewriteCond %{REQUEST_URI} ^/backend/web
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /backend/web/index.php

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Natarov, 2016-03-03
@HanDroid

It's in .htacces

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

It's in frontend/config/main.php that you have all the rules connected, it's just that the rules in the RegExp format are not correctly specified or what do you have in the rules?
'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                '/' => 'site/index'
             /* другие правила */
            ],
        ],

W
websteam, 2016-03-03
@websteam

Can you elaborate on what kind of error you have, how you set the routing, that is, the rules, and how to understand the styles are disabled, that is, you have some css files that stop loading when you click on some link. In general, the urlManager component is connected like this

'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                           'название ссылки' => 'имя контроллера/имя экшена'
            ]
        ]

and then the links are generated using the yii\web\Url::toRoute() helper

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question