我隐藏了index.php,并使用以下代码使url友好
. htaccess
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
在主配置中,
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
),
),
它按预期工作,但问题是当输入不存在的url时,它总是重定向到登录页面"site/login"。所以,如果url是错误的/不存在,而不是显示404,它重定向到登录页面。我做错了什么?
检查客户访问actionError的权限。您还可以在apache中打开LogLevel调试来跟踪重写规则。但是比起重写
当使用Path urlFormat
时,您需要激活useStrictParsing
以呈现错误URL的404页面,修改您的配置如下
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName' => false,
'useStrictParsing'=>true,
'rules'=>array(
),
),
详情请参阅http://www.yiiframework.com/doc/api/1.1/CUrlManager#useStrictParsing-detail