Enable clean URL in Yii2 - yii2

How can I enable clean urls in Yii2. I want to remove index.php and '?' from url parameters. Which section needs to be edited in Yii2 for that?

I got it working in yii2. Enable mod_rewrite for Apache.
For basic template do the following:
Create a .htaccess file in web folder and add this
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
Then inside config folder, in web.php add to components
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
],
In the case of advanced template create the .htaccess files inside backend/web and frontend/web folders and add urlManager component inside common/config/main.php

First important point is that
Module_Rewrite is enabled on your server(LAMP,WAMP,XAMP..etc)
For do URL rewiring in yii2 framework Create one .htaccess file and put in /web folder
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
Second step
Config folder common/config/main-local.php add to components array
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
],

For me, the problem was:
Missing .htaccess in the web folder just like mentioned above.
The AllowOverride directive was set to None, which disabled URL rewrites. I changed it to All and now pretty URLs work nicely.
<Directory "/path/to/the/web/directory/">
Options Indexes
FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>

First, create a .htaccess at root folder in your Yii2 project with following content:
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]
Create another .htaccess file in your web folders with following content:
frontend/web/ add backend/web/
Don't forget to add .htaccess file to both web folders:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
Now It's done. Change your URL configuration in Yii2:
<?php
use \yii\web\Request;
$baseUrl = str_replace('/frontend/web', '', (new Request)->getBaseUrl());
$config = [
'components' => [
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'aiJXeUjj8XjKYIG1gurMMnccRWHvURMq',
'baseUrl' => $baseUrl,
],
"urlManager" => [
'baseUrl' => $baseUrl,
'enablePrettyUrl' => true,
'showScriptName' => false,
"rules" => [
"home" => "site/index",
"about-us" => "site/about",
"contact-us" => "site/contact",
]
]
],
];
return $config;
Your URL will change to:
localhost/yii2project/site/about => localhost/yii2project/about-us
localhost/yii2project/site/contact => localhost/yii2project/contact-us
localhost/yii2project/site/index => localhost/yii2project/home
You can access your admin through
localhost/yii2project/backend/web

on nginx configure like that
location / {
try_files $uri $uri/ /index.php$is_args$args;
}

Just to add to this discussion - I've just installed Yii2, and it includes the following commented-out code in config/web.php:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [],
],
If you add the .htaccess file in the accepted answer, then just uncomment the above, pretty URLs will work (I have no idea what the "rules" in the accepted answer are for, but everything seems to work without them).

Step 1: Put .htaccess file in 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]
Step 2: Put .htaccess file in frontend/web.
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
Step 3: Then changes in frontend/config/main.php. Following code need to be added inside 'components' => [].
'request' => [
'csrfParam' => '_csrf-frontend',
'baseUrl' => '/yii-advanced', //http://localhost/yii-advanced
],
'urlManager' => [
'class' => 'yii\web\UrlManager',
'showScriptName' => false, // Disable index.php
'enablePrettyUrl' => true, // Disable r= routes
'rules' => array(
'about' => 'site/about',
'service' => 'site/service',
'contact' => 'site/contact',
'signup' => 'site/signup',
'login' => 'site/login',
),
],
Above steps are worked for me.

Step-by-step instruction
Step 1
At the root of the project add a .htaccess with the following content:
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
Step 2
In the folder /web add a .htaccess file with the following content:
RewriteEngine On RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
Step 3
In the file /config/web.php in element components of array add folowing code:
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'yYy4YYYX8lYyYyQOl8vOcO6ROo7i8twO',
'baseUrl' => ''
],
//...
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'' => 'site/index',
'<controller:\w+>/<action:\w+>/' => '<controller>/<action>',
],
],
Done..

What worked for me-
create a .htaccess at root folder of my Yii2 project, and added following-
<IfModule mod_rewrite.c>
Options +FollowSymlinks
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>
Created new .htaccess file web folders with following content:
frontend/web/
and added following-
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
Then added urlmanager here-
projectFolder/common/config/main.php
For me it was not there, so added this as-
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
/* 'rules' => [
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
],*/
],
Make sure this code must be in 'components' => [].
Restart my server and everything works fine.

Step1: in project config/main.php eg: frontend/config/main.php
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [],
]
Step2: create .htaccess file inset web folder eg: frontend/web
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
#php_flag display_errors on
#php_value error_reporting 2039

Just add below code to your config file.
'urlManager' => [
'enablePrettyUrl' => true,
'rules' => [
// your rules go here
],
// ...
]

if you have installed yii2 application theme
go to basic/web/
inside -> .htaccess "paste code below if not exist"
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
then go to config/
inside web.php uncomment line starting from 47 to 52 (lines may be changed) or something similar to this..
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],

I installed a new version of this framework.
In backend/config/main.php, you can see the code that is commented you can use this and do this for the frontend folder`.

config/web.php
$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['log'],
'aliases' => [
'#bower' => '#vendor/bower-asset',
'#npm' => '#vendor/npm-asset',
],
'components' => [
'assetManager' => [
// override bundles to use local project files :
'bundles' => [
'yii\bootstrap4\BootstrapAsset' => [
'sourcePath' => '#app/assets/source/bootstrap/dist',
'css' => [
YII_ENV_DEV ? 'css/bootstrap.css' : 'css/bootstrap.min.css',
],
],
'yii\bootstrap4\BootstrapPluginAsset' => [
'sourcePath' => '#app/assets/source/bootstrap/dist',
'js' => [
YII_ENV_DEV ? 'js/bootstrap.js' : 'js/bootstrap.min.js',
]
],
],
],
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => 'V_Pj-uMLTPPxv0Be5Bwe3-UCC6EjGRuH',
'baseUrl' => '',
],
'formatter' => [
'dateFormat' => 'dd/MM/yyyy',
'decimalSeparator' => ',',
'thousandSeparator' => '.',
'currencyCode' => 'BRL',
'locale' => 'pt-BR',
'defaultTimeZone' => 'America/Sao_Paulo',
'class' => 'yii\i18n\Formatter',
],
'datehelper' => [
'class' => 'app\components\DateBRHelper',
],
'formatcurrency' => [
'class' => 'app\components\FormatCurrency',
],
'request' => [
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
'cookieValidationKey' => '123456',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
// send all mails to a file by default. You have to set
// 'useFileTransport' to false and configure a transport
// for the mailer to send real emails.
'useFileTransport' => true,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => $db,
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'enableStrictParsing' => true,
'rules' => [
'' => 'site/index',
'<controller:\w+>/<action:\w+>/' => '<controller>/<action>',
],
],
],
'params' => $params,
];
if (YII_ENV_DEV) {
// configuration adjustments for 'dev' environment
$config['bootstrap'][] = 'debug';
$config['modules']['debug'] = [
'class' => 'yii\debug\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
$config['bootstrap'][] = 'gii';
$config['modules']['gii'] = [
'class' => 'yii\gii\Module',
// uncomment the following to add your IP if you are not connecting from localhost.
//'allowedIPs' => ['127.0.0.1', '::1'],
];
}
return $config;
arquivo .htaccess na pasta raiz
<IfModule mod_rewrite.c>
Options +FollowSymlinks
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 dentro da pasta web/
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

Related

Yii2 Backend show 500 internal server error

When I access http://alpha.myweb.com/administrator/company I got 500 Internal Server Error
But I can access it localhost.
How I can debug my problem?
Here is my backend\config\main.php
<?php
$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-backend',
'basePath' => dirname(__DIR__),
'controllerNamespace' => 'backend\controllers',
'bootstrap' => ['log'],
'modules' => [
'agent' => [
'class' => 'backend\modules\agent\Agent',
],
'company' => [
'class' => 'backend\modules\company\Company',
'defaultRoute' => 'home',
],
'vendor' => [
'class' => 'backend\modules\vendor\Vendor',
'defaultRoute' => 'default',
],
'services' => [
'class' => 'backend\modules\services\Services',
'defaultRoute' => 'site',
],
],
'homeUrl' => 'http://alpha.myweb.com/administrator',
'components' => [
'formatter' => [
'class' => 'yii\i18n\Formatter',
'thousandSeparator' => '.',
'decimalSeparator' => ',',
//'currencyCode' => '$'
],
'user' => [
'identityClass' => 'common\models\UserBeo',
'enableAutoLogin' => false,
//'authTimeout' => 120
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'urlManager' => [
'class' => 'yii\web\UrlManager',
'enablePrettyUrl' => true,
'showScriptName' => false,
'showScriptName' => false,
/*
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
*/
],
'request' => [
'baseUrl' => '/administrator',
'parsers' => [
'application/json' => 'yii\web\JsonParser',
]
],
/*
'response' => [
'format' => yii\web\Response::FORMAT_JSON,
'charset' => 'UTF-8',
// ...
]
*/
],
'params' => $params,
];
Here is my .htaccess
# prevent directory listings
Options -Indexes
IndexIgnore */*
# follow symbolic links
Options FollowSymlinks
RewriteEngine on
RewriteRule ^administrator(/.+)?$ backend/web/$1 [L,PT]
RewriteRule ^(.+)?$ frontend/web/$1
#RewriteCond %{HTTP_HOST} ^alpha\.myweb\.com [NC]
#RewriteRule ^(.*)$ http://alpha.myweb.com/$1 [L,R=301]
So What cause this problem, because I can open frontend website without error.
Please let me know if you need more information.
Thanks in advance, any help appreciated.

rest yii2 pretty url urlManager

My yii2 rest work fine with this request
http://extractor-frontend.dev/property?id=JP000004
i would to work with this
http://extractor-frontend.dev/property/JP000004
this is my urlManager in config/web.php
urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
[
'class'=>'yii\rest\UrlRule',
'pluralize' => false,
'controller' => 'property',
'tokens' => [
'{id}' => '<id:\\w+>'
],
'extraPatterns' => ['GET,HEAD property/{id}' => 'index',]
]
],
],
this is my .htaccess in web
RewriteEngine on
Options Indexes
Require all granted
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . index.php
if put 'enableStrictParsing' => false,
http://extractor-frontend.dev/site/about
work fine ... rewrite rules works!
I use below code for my yii2 apps. I think your config method is eligible for yii1. It is recommended to use yii2 config method.
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'myaction/<id>/<param2>' => 'site/myaction',
[
'pattern' => '<action>',
'route' => 'site/<action>',
'defaults' => ['action' => 'index']
],
]
]

YII2 RESTFUL 404

I search for this get less infomesion while I doing
my config (rest.php)
<?php
$params = require(__DIR__ . '/params.php');
$config = [
'id' => 'rest-api',
'basePath' => dirname(__DIR__),
'language' => 'zh-CN',
'controllerNamespace' => 'rest\controllers',
'bootstrap' => ['log'],
'modules' => [
'v1' => [
'class' => 'rest\versions\v1\Module',
],
],
'components' => [
'errorHandler' => [
'errorAction' => 'site/index',
],
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
[
'class' => 'yii\rest\UrlRule',
'controller' => [
'v1/product',
],
]
],
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => require(__DIR__ . '/db.php'),
'request' => [
'parsers' => [
'application/json' => 'yii\web\JsonParser',
]
],
],
'params' => $params,
];
return $config;
my Module.php
<?php
namespace rest\versions\v1;
use Yii;
use yii\base\Module;
class Module extends Module
{
public $controllerNamespace = 'rest\versions\v1\controllers';
public function init()
{
parent::init();
}
}
my .htaccess file,it's code like this.
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
MY PRODUCT CONTROLLER
<?php
namespace rest\versions\v1\controllers;
use Yii;
use yii\rest\ActiveController;
class ProductController extends ActiveController
{
public $modelClass = 'rest\versions\v1\models\Product';
public function actionIndex()
{
return 'haha';
}
}
I still get the 404
http://rest.mcolor.com/v1/products
I got the info
404 Not Found
nginx/1.8.1
plz help me.
It looks like you are using .htaccess file for rewrites, but at your server is installed nginx web server(you can see that at 404 response body.)
So you can use some example of nginx config from tutorial and change domains, path, etc:
server {
charset utf-8;
client_max_body_size 128M;
listen 80; ## listen for ipv4
#listen [::]:80 default_server ipv6only=on; ## listen for ipv6
server_name mysite.local;
root /path/to/basic/web;
index index.php;
access_log /path/to/basic/log/access.log;
error_log /path/to/basic/log/error.log;
location / {
# Redirect everything that isn't a real file to index.php
try_files $uri $uri/ /index.php?$args;
}
# uncomment to avoid processing of calls to non-existing static files by Yii
#location ~ \.(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
# try_files $uri =404;
#}
#error_page 404 /404.html;
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
#fastcgi_pass unix:/var/run/php5-fpm.sock;
try_files $uri =404;
}
location ~ /\.(ht|svn|git) {
deny all;
}
}

yii2 disable access by right part of routing rule

In web.php I have following code:
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
'rules' => array(
'calc' => 'site/calc',
),
],
And I want to allow users to access to example.com/calc but not to example.com/site/calc. How I can do it properly with less effort? By other words now works both options - "site/calc" and "calc" and I want to disable "site/calc".
Try to add enableStrictParsing to UrlManager configuration as follows
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'rules' => array(
'calc' => 'site/calc',
),
],
In this case if there's no rule matching the request then it's considered as bad one.

yii2 url not found shown while accessing controller action

I have created a controller function like
public function actionRateTicket($id){
}
The urlManager has the following configuration
'urlManager' => [
'class' => 'yii\web\UrlManager',
// Disable index.php
'showScriptName' => false,
// Disable r= routes
'enablePrettyUrl' => true,'enableStrictParsing' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
],
But when I tried to access http://mydomainname/web/ticket/rate-ticket/2333 , (ticket is the name of controller(TicketController.php)) it is showing Not Found (#404) error.
What is the problem here?
I am able to access all controller actions with a single camel case characters like actionView, actionEdit etc, but actionRateTicket, I am not able to acess. If the actionRateTicket is renamed to actionRate, it is working.
My controller is like this
<?php
namespace app\controllers;
use Yii;
use app\models\Techs;
use app\models\Ticket;
use app\models\Assignment;
use app\models\TicketSearch;
use app\models\ComplainType;
use app\models\TicketComplain;
use app\models\User;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use app\models\Adusers;
use yii\web\UploadedFile;
use app\helpers\Utils;
use yii\db\Expression;
use yii\filters\AccessControl;
/**
* TicketController implements the CRUD actions for Ticket model.
*/
class TicketController extends Controller {
public function behaviors() {
return [
'access' => [
'class' => AccessControl::className(),
'only' => [
'index',
'view',
'update',
'delete',
'newticket'
],
'rules' => [
[
'actions' => [
'index',
'view',
'update',
'delete',
'newticket'
],
'allow' => true,
'roles' => ['#'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['post'],
],
],
];
}
public function actionRateTicket($id) {
echo "in"; echo $id;
exit;
}
}
?>
My .htaccess of web folder is
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
Change the action name for actionRateticket, and the call should be http://mydomainname/web/ticket/rateticket/2333 with rateticket.
try using the following line:
use yii\helpers\Url;
I believe it is because of the weird way that Yii uses dashes instead of camel case. Try changing your rules from <action:\w+> to <action:[-\w]+> since the dash is not a word character!
I can't find the default rules to verify that they also check for the dash but that should work.
you need to specify the action in access behavior
'access' => [
'class' => AccessControl::className(),
'only' => ['rate-ticket', 'index','view','update','delete','newticket' ],
'rules' => [
[
'actions' => ['rate-ticket', 'index','view','update','delete','newticket', ],
'allow' => true,
'roles' => ['#'],
],
],
],
yii2 uses more SEO friendly url for camel case controller. All camel case is converted to lowercase with dash like this:
UserProfileController
index.php?r=user-profile