S
S
Sergey2016-03-10 10:31:54
Yii
Sergey, 2016-03-10 10:31:54

How to configure UrlManager correctly?

Using advanced, I set up UrlManager in common/config/main.php like this

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

        ],

then try to use like this
<li><a href="<?= Yii::$app->urlManager->createUrl(['/blog/list']) ?>">Блог</a></li>

gives the address of blog/list (that is, without the domain name). Explain what I'm doing wrong? And how to configure it correctly so that the address would be conditionally mysite/blog/list (well, or at worst mysite/frontend/web/blog/list.
here is .htaccess
<IfModule mod_rewrite.c>
        Options +FollowSymlinks
        RewriteEngine On
    </IfModule>
     

    <IfModule mod_rewrite.c>
        RewriteCond %{REQUEST_URI} ^/(admin)
        RewriteRule ^admin/assets/(.*)$ backend/web/assets/$1 [L]
        RewriteRule ^admin/css/(.*)$ backend/web/css/$1 [L]

    RewriteCond %{REQUEST_URI} !^/backend/web/(assets|css)/
    RewriteCond %{REQUEST_URI} ^/(admin)
    RewriteRule ^.*$ backend/web/index.php [L]

    RewriteCond %{REQUEST_URI} ^/(assets|css|js|images)
    RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
    RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
    RewriteRule ^js/(.*)$ frontend/web/js/$1 [L]
    RewriteRule ^images/(.*)$ frontend/web/images/$1 [L]
    RewriteRule ^(.*)$ frontend/web/$1 [L]

    RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css|js)/
    RewriteCond %{REQUEST_URI} !index.php
    RewriteCond %{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^.*$ frontend/web/index.php
</IfModule>

here is frontend/config/main.php
'request' => [
                'baseUrl' => '/'
            ],

here is frontend/web/.htaccess
<IfModule mod_autoindex.c>
          Options -Indexes
    </IfModule>
        
    <IfModule mod_rewrite.c>
          Options +FollowSymlinks
          RewriteEngine On
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule . index.php
    </IfModule>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question