如何在apache/.htaccess/mod_rewrite中隐藏yii的index.php文件?
我有一个htaccess文件:如何在apache/.htaccess/mod_rewrite中隐藏yii的index.php文件?,php,apache,.htaccess,mod-rewrite,yii,Php,Apache,.htaccess,Mod Rewrite,Yii,我有一个htaccess文件: RewriteEngine on #if a directory or a file exists, use it directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php RewriteEngine on # if a directory or a file exists, use it directly Tr
RewriteEngine on
#if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
RewriteEngine on
# if a directory or a file exists, use it directly
TryToForceA500
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
我使用的是Yii 1.1.15(这个网站是从1.1.13版本中获取的,但是这个版本已经不能下载了,所以我在1.1.15框架安装中使用了它——尽管据我所见它没有问题),有一个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'=>'webmaster@example.com',
),
);
我认为您需要启用mod_rewrite,请尝试:
a2enmod rewrite
然后重新启动服务器。我找到了答案在确保我的其他站点的mod_rewrite处于活动状态后,我问自己:我的.htaccess被识别了吗
所以我想通过破坏我的.htaccess文件来强制执行500错误:
RewriteEngine on
#if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
RewriteEngine on
# if a directory or a file exists, use it directly
TryToForceA500
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
没有触发任何错误!所以我再次问自己:为什么它没有被识别?并检查了my site.conf文件,发现:
AllowOverride none
并改为:
AllowOverride all
(这只是一个开发服务器,所以安装对我来说很好)
然后文件被识别并工作了 否,它已启用。否则我会有500个错误。顺便说一句,我现在试过这个命令,但都没用。虽然你写的答案不是我问题的答案(我找到了),但这是人们发现的一个常见问题,我不久前也发现了。确保mod_rewrite处于活动状态在apache中并不重要(尽管它在nginx中的“表亲”很重要),而且大多数时候它是解决方案。投票:)。