Yii URL隐藏index.php

一.修改config/下的main.php里的

'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>',
    ),
),
'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>',
    ),
),

二.修改网站根目录下.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
location / {
  if (!-e $request_filename){
    rewrite ^/(.*) /index.php last;
  }
}
if (!-e $request_filename) {
  rewrite ^(.+)$ /index.php?q=$1 last;
}

留下评论

鄂ICP备13000209号-1

鄂公网安备 42050602000277号