使用URL重写,去掉index.php

来源:互联网 发布:淘宝机器人在哪 编辑:程序博客网 时间:2024/05/01 09:22

1、在httpd.conf中打开apache的rewrite模块

#LoadModule rewrite_module modules/mod_rewrite.so

将前面的“#”去掉

将“AllowOverride None”改为“AllowOverride All

2、在你的app根目录下创建.htaccess内容如下:

<IfModule mod_rewrite.c> 
  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 
</IfModule>

3、修改config/main.php,在刚才UrlManager组件增加属性showScriptName,值为false.

'urlManager'=>array( 
     'urlFormat'=>'path', //使用pathinfo模式
     'showScriptName'=>false,//不显示脚本名
 ),

4、重启apache

原创粉丝点击