yii url重写去掉index.php

时间:2021-05-24 19:58:41
步骤一:

打开protected\config\main.php 打开该段注释…

'urlManager'=>array(
'urlFormat'=>'path', //使用pathinfo模式,不需要?r=
'showScriptName'=>false, //将代码里链接的index.php隐藏掉。
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),

步骤二:
nginx下:
.htaccess 加入如下代码:(或是nginx.conf 那里设置?)

location / {  
if (!-e $request_filename){
rewrite ^/(.*) /index.php last;
}
}
apache下:
.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