Hi there!
I am new to Yii framework at all. Recently I was using Kohana framework and now I want to master Yii2. What is giving me a headache is routing in Yii. I am using basic application template and here is my problem:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'' => 'site',
],
],
So I configured urlManager like this. In Kohana it would mean, that only empty request is allowable. For example, ‘mydomain.com’. My controller Site has action Index set as defaultAction. But I can still access it with requests via ‘index.php’ i.e. “mydomain.com/index.php”, “mydomain.com/index.php?r=site/index”, “mydomain.com/site/index” etc. I solved the ‘controller/action’ availability by enabling strict parsing. But with ‘index.php’ case I was adviced on to add following lines to .htaccess RewriteEngine rules:
RewriteCond %{THE_REQUEST} index\.php
RewriteRule ^ / [L,R=404]
Is this proper way to solve this? Right now my .htaccess looks like this:
RewriteEngine on
RewriteCond %{THE_REQUEST} index\.php
RewriteRule ^ / [L,R=404]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
Is this fine? It works as I want it to, but I am curious about another ways to hanlde it (maybe Yii2 has some proper ways). And another question - in case I want to restrict from direct access (via client ‘controller/action’ requests) only few actions (enableStrictParsing = false) what should I do? Use rules like that:
'controller/restricted-action' => 'error/404'
?