我有这个htaccess文件:如何在apache/.htaccess/mod_rewrite中隐藏yii的index.php文件?
RewriteEngine on
#if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
而且我使用Yii 1.1.15(这个网站是从1.1.13采取版本,但是这样的版本不再提供下载,所以我在1.1.15框架使用它安装 - althought却没有这个问题,据我所看到的),有喜欢的conf/main.php文件:
<?php
return array(
'basePath'=>dirname(dirname(__FILE__)),
'name'=>'Grand Duval - Códigos premiados',
'defaultController'=>'participantes/create',
'language'=>'es',
// preloading 'log' component
'preload'=>array('log'),
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
),
'modules'=>array(
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'mypassword',
'ipFilters'=>array('127.0.0.1', '::1'),
),
),
// application components
'components'=>array(
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>true,
),
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=mydatabase',
'emulatePrepare' => true,
'username' => 'sbuser',
'password' => 'dbpassword',
'charset' => 'utf8',
),
'errorHandler'=>array(
'errorAction'=>'site/error',
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
),
),
),
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params'=>array(
// this is used in contact page
'adminEmail'=>'[email protected]',
),
);
的重要组成部分,这里是:
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
这样的配置旨在 - 并且确实如此 - 为控制器controller
和动作action
生成绝对url,如http://www.mydomain.dev/controller/action
。
我与.htaccess
文件有问题:如果我尝试点击http://www.mydomain.dev/controller/action
,则找不到网址。但是,如果我点击http://www.mydomain.dev/index.php/controller/action
它被发现。看起来.htacccess
根本没有任何效果(如果我删除.htaccess文件,则完全相同)。
问题:我做错了什么?
不,它已启用。否则,我会得到一个500错误。顺便说一句,我现在试过这个命令,但都没有工作 – 2014-09-26 14:31:10
虽然你写的答案不是我的问题的答案(我发现它),但这是人们发现的一个常见问题,而且我前一段时间发现了这个问题。在Apache中确保mod_rewrite是活动的并不是微不足道的(尽管它在nginx中的'表哥'是微不足道的),而且大部分时间都是解决方案。 upvote :)。 – 2014-09-26 14:38:36