php框架

 首页 > php框架 > YII > YII URL重写(开启伪静态)

YII URL重写(开启伪静态)

分享到:
【字体:
导读:
          目标:把这个url重写成下面那种 http://localhost/yii/index.php?r=site/login http://localhost/yii/site/login 一、确定你的apache有rewrite模块,可以通过phpinfo()来查看。 没有怎么办?自己百度 二、编辑y...

目标:把这个url重写成下面那种

http://localhost/yii/index.php?r=site/login

http://localhost/yii/site/login

一、确定你的apache有rewrite模块,可以通过phpinfo()来查看。

没有怎么办?自己百度

二、编辑yii的配置文件 main.php

找到

1
2
3
4
5
6
7
8
9
10
/*
 'urlManager'=>array(
 'urlFormat'=>'path',
 'rules'=>array(
 '/'=>'/view',
 '//'=>'/',
 '/'=>'/',
 ),
 ),
 */

把注释去掉

现在应该可以看到效果了,但是还是有写瑕疵,我们要吧入口文件index.php去掉

三、在网站根目录新建一个文件.htaccess

1
2
3
4
5
6
7
8
9
<IfModule rewrite_module>
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine On
 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

ok虽然去掉index.php也不报错,但是默认路径还是带了index.php

最后一步,更改配置文件main.php

找到

1
'urlFormat'=>'path',

在它下面增加

1
'showScriptName'=>false,

大功告成!!

分享到:
YII URL 伪静态设置2
主要实现这样的url : http://localhost:84/site/contact.html  配置方法:在config/main.php中的‘components’数组中添加   //URL管理         &#039;urlManager&#039;=>array(             &#039;urlFormat&#039;=>&#039;path&#039;,           ...
YII公用控制器_yii控制器共继承
如果你的项目中有控制器需要共用,其实只需要在config/main.php中加入一小段代码即可实现: XML/HTML代码 &#039;controllerMap&#039;=>array(       &#039;xxx&#039;=>&#039;ext.XxxController&#039;   ),   然后就可以直接调用了:index.php?r=xxx/index,即可以调用Xx...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……