C
C
CodeBuilder2015-08-31 22:39:49
Yii
CodeBuilder, 2015-08-31 22:39:49

Yii2 pretty Url Advanced adds controller name to URL, what am I doing wrong??

Save me, I'm suffering for half a day.
Trying to make pretty links in yii2 advanced template:
Here is the .htaccess at the root:

Options -Indexes

<IfModule mod_rewrite.c> 
  RewriteEngine on

  RewriteCond %{REQUEST_URI} !^public
  RewriteRule ^(.*)$ frontend/web/$1 [L] 
</IfModule>

# Deny accessing below extensions
<Files ~ "(.json|.lock|.git)">
Order allow,deny
Deny from all
</Files>

# Deny accessing dot files
RewriteRule (^\.|/\.) - [F]

Here is the .htaccess in frontend/web/:
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

Here is frontend/config/main.php:
use \yii\web\Request;
$baseUrl = str_replace('/frontend/web', '', (new Request)->getBaseUrl());
$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'),
    require(__DIR__ . '/../../common/config/params-local.php'),
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/params-local.php')
);

return [
    'id' => 'app-frontend',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'controllerNamespace' => 'frontend\controllers',
    
    'components' => [
    
   'request' => [
            'baseUrl' => $baseUrl,
        ],
        'mailer' => [
                'class' => 'yii\swiftmailer\Mailer',
                'useFileTransport' => false,
                'transport' => [
                	'class' => 'Swift_SmtpTransport',
                	'host' => 'smtp.gmail.com',
                	'username' => '[email protected]',
                	'password' => 'everestpro',
                	'port' => '587',
                	'encryption' => 'tls'
                ]
            ],
        
         
            'user' => [
                'identityClass' => 'common\models\User',
                'enableAutoLogin' => false,
            ],
            'log' => [
                'traceLevel' => YII_DEBUG ? 3 : 0,
                'targets' => [
                    [
                        'class' => 'yii\log\FileTarget',
                        'levels' => ['error', 'warning'],
                    ],
                ],
            ],
            'errorHandler' => [
                'errorAction' => 'site/error',
            ],
        'authManager' => [
          'class' => '\yii\rbac\DbManager',
        ],
    
          'urlManager' => [
            'baseUrl' => $baseUrl,
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'rules' => []
        ],
        
        
        
    ],
    
  
  
    'params' => $params,
];

It seems that I didn’t miss anything, I did everything according to the guide, but for some reason the name of the controller is pasted into the links to images and to Ajax (post request). Any ideas?
545472da580c4a6ca66754b42b8dd1e3.jpg797552207acb422cb403a7752637d5cb.jpg

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