K
K
knowledge2018-07-17 00:18:41
Yii
knowledge, 2018-07-17 00:18:41

Why are pretty links not working in Yii2?

I installed yii2 via composer I
registered the root directory - project / web in the apache settings, to get rid of web / index.php I
put .htaccess with the content in the web folder

<IfModule mod_rewrite.c>    
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule . index.php
</IfModule>

and uncommented UrlManager
In a word, one to one for tutorials (as well as for one video lesson) which, however, is absolutely the same.
and now the site opens through project/
I follow the link project/site/about
bang.... 404 Not Found...
Magic...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pios88, 2018-07-17
@Pios88

It worked for me like this:
web/config.php :

'components' => [
        'request' => [
            'baseUrl' => ''
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                '' => 'site/index',
            ],

.htaccess at the root:
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine On
 
RewriteCond %{REQUEST_URI} !^/(web)
RewriteRule ^assets/(.*)$ /web/assets/$1 [L]
RewriteRule ^css/(.*)$ web/css/$1 [L]
RewriteRule ^js/(.*)$ web/js/$1 [L]
RewriteRule ^images/(.*)$ web/images/$1 [L]
RewriteRule (.*) /web/$1
 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /web/index.php

.htaccess in web folder:
RewriteEngine On RewriteBase /
 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
 
RewriteRule . index.php

Without 'rules' => [ '' => 'site/index', ], - it's also possible, but then the routing works, but the styles move off, although for some reason everything worked in the video tutorials for their authors :)
I'm talking about Yii2 basic.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question