Z
Z
ZaurK2018-06-07 09:36:04
Yii
ZaurK, 2018-06-07 09:36:04

How to write a rule to change the link to the admin page?

Hello! On yii2 basic, the admin is located in a separate module and is available at mysite.loc/web/login and mysite.loc/web/site/login. I would like the admin panel to be available at mysite.loc/admin.
Can you please tell me where and how to set it up? Or in .htaccess or in urlManager?
Admin is implemented as a module:
....
modules
-admin
--controllers
--models
...
web
views
...

'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => [
           '' => 'site/index',
                '<action>'=>'site/<action>',
        'admin' => 'site/login',

            ],
        ],

.htaccess file at the root:
<IfModule mod_rewrite.c>
    Options +FollowSymlinks
  IndexIgnore */*
    RewriteEngine On
</IfModule>
 
<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_URI} ^/.*
    RewriteRule ^(.*)$ web/$1 [L]

    RewriteCond %{REQUEST_URI} !^/web/
    RewriteCond %{REQUEST_FILENAME} !-f [OR]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^.*$ web/index.php
</IfModule>

.htaccess file in web folder:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2018-06-07
@qonand

You need to:
1. Get rid of the web in the address, how to do this, you can google information on this topic is full
2. Register the url rule in the url manager, ala:

[
    // ...
    'admin' => 'site/login',
];

L
Lander, 2018-06-07
@usdglander

First: configure the virtual host to look in the web folder
Second: add a rule to the urlManager
'admin' => 'site/login'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question