yii重写url

开启 rewrite模块儿

步骤一:
打开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

猜你喜欢

转载自blog.csdn.net/giscong/article/details/77884358