【发布时间】:2015-08-08 13:22:21
【问题描述】:
我可以在 Yii 中制作漂亮的 URL
example.com/readings/view?BookID=9955
首先,readings 是我的默认控制器,所以我不希望它的操作以它的名称为前缀,即:
example.com/view?BookID=9955
其次,我需要忽略?BookID=:
example.com/view/9955
我也有书籍分页:
example.com/readings/view?BookID=9955&start=2我需要它
example.com/readings/view/9955/2
我的 URLManager 配置是:
'defaultRoute' => 'readings/index',
//'catchAll' => ['site/offline'],
'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>',
),
],...
还有.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
【问题讨论】:
标签: .htaccess yii2 friendly-url