V
V
Vitaly Slyusar2016-03-16 16:54:55
Yii
Vitaly Slyusar, 2016-03-16 16:54:55

Why doesn't routing work in Yii2? on openserver?

In short, I watched the lessons, searched the Internet, found the routing code in yii2:

'urlManager' => [
            'class' => 'yii\web\UrlManager',
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
            ]
        ],

.htaccess
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

moved index.php to the root, configured paths to css and files.
When I click on the index, the path is basic/index.php?r=site%2Findex
When I type site/index/, the path is basic/site/index
But when I try to type site/about, the path is basic/site/about
BUT instead of about the main page is displayed. And you can write whatever you want in the url, it's still the main page.
Where did I mess up?? Tell! Thank you in advance.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Mylistryx, 2016-03-17
@slusarvitaliy

The simplest solution:
1. In the open server, enable domain management Manual + Autosearch (you can just manually)
2. Add a domain (for example) test.local, a folder for it \basic\web
Restart the server and everything works!
For the advanced template, I create 2 domains, for example, test.local in the \advanced\frontend\web folder and admin.test.local in the \advanced\backend\web folder.
This config allows you not to fence in .htaccess, but to use the default version.
Well, to check, clear the rules array in the UrlManager config, i.e. 'rules' => []

M
Maxim Timofeev, 2016-03-17
@webinar

I’ll add to what Mylistryx wrote , so that it would be easier to transfer it to the server later, we create the mysite folder in the domains folder, the yii folder in it and next to it the public_html folder, we throw the entire framework into yii, everything from the basic / web folder to public_html.
Next:
1. In the open server, enable Manual + Autosearch domain management (you can just manually)
2. Add a domain (for example) mysite .local, the folder for it is \mysite\public_html
3. Edit the paths in index.php, according to the new location
Restart the server and everything works!
Thus, we take the framework out of the public folder, which is good.

M
maks280795, 2016-03-16
@maks280795

Do you have a corresponding actionAbout() action in the SiteController?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question