In Yii2, I cannot enable pretty url's.
My config:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
],
My .htaccess:
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 script:
echo 'enablePrettyUrl: ';
echo Yii::$app->urlManager->enablePrettyUrl ? 'true ' : 'false';
echo '<br>';
echo 'enableStrictParsing: ';
echo Yii::$app->urlManager->enableStrictParsing ? 'true ' : 'false';
echo '<br>';
echo 'showScriptName: ';
echo Yii::$app->urlManager->showScriptName ? 'true ' : 'false';
echo Url::to(['/book/read', 't' => 'booktitle', 'c'=>'chaptertitle']);
The output from the script:
enablePrettyUrl: true
enableStrictParsing: false
showScriptName: false
/book/read?t=booktitle&c=chaptertitle
Clearly, I am not getting pretty Url's. Why not?
- We know
enablePrettyUrl=== true
- I do not believe there is anything wrong with my .htaccess
/book/read/booktitle/chaptertitle
. Did this change between Yii 1.1 and Yii 2? – Compline