【发布时间】:2015-02-03 04:40:26
【问题描述】:
我正在学习 Yii 2.0 框架。我这样配置 urlManager:
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'' => 'site',
],
],
SiteController 只有一个动作——actionIndex(默认一个)。我想要的是只能访问“mydomain.com”(所有其他请求都会导致 404 错误)。但现在我可以通过多种方式调用“站点/索引”操作:
- mydomain.com
- mydomain.com/site/index
- mydomain.com/index.php
- mydomain.com/index.php/site/index
- mydomain.com/index.php?r=site/index
... 等等。我的 .htaccess 文件是:
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if request dosn't start with web add it
RewriteCond %{REQUEST_URI} !^/(web)
RewriteRule (.*) $1
# if file or directory dosn't exists go to /web/index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
那么我怎样才能限制所有这些并让我的应用程序仅使用 urlManager 规则中直接指定的路由?
【问题讨论】: