1、开启apache的mod_rewrite模块
#去掉LoadModule rewrite_module modules/mod_rewrite.so前的“#”符号 #如果是ubuntu系统,系统默认是开启rewrite的 cd /etc/apache2/mods-enabled #查看是否有rewrite.load链接文件,如果没有则建立链接文件 cd /etc/apache2/mods-enabled ln -s ../mods-available/rewrite.load rewrite.load//这一步未验证
2、确保 <Directory "..."></Directory>中有“AllowOverride All”
下面是一个示例,其他情况类似:
#现有一个工程project,需要配置虚拟主机文档 cd /etc/apache2/sites-available sudo vi project #放入如下内容 <VirtualHost *:80> ServerAdmin [email protected] ServerName baike.petshome.cn DocumentRoot /var/www/project <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory /var/www/project> Options FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> #然后确保AllowOverride All即可
3、修改项目配置文件,在项目中的/protected/config/main.php中修改代码
‘components‘=>array(
...
‘urlManager‘=>array(
‘urlFormat‘=>‘path‘,
‘showScriptName‘=>false,//注意false不要用引号括上
...
),
4、在与index.php文件同级目录下添加文件".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
这样便可隐藏index.php入口文件了。
参考资料:http://www.yiiframework.com/forum/index.php/topic/1061-%e9%9a%90%e8%97%8findexphp%e7%9a%84%e6%ad%a5%e9%aa%a4/
Yii隐藏入口文件index.php,布布扣,bubuko.com
时间: 2024-10-10 11:06:15