yii框架如何配置pathinfo的模式

  介绍

这篇文章给大家分享的是有关yii框架如何配置pathinfo的模式的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。

<强> yii框架怎么配置pathinfo的模式,,

第一次部署好Yii框架搭建的应用后,框架默认使用的不是PathInfo形式的URL,而是类似http://yourdomain.com/index.php?r=账户/登录这样的形式,这种URL不仅不美观,而且不利于搜索引擎优化,所以下面介绍在Yii中如何使用PathInfo形式的URL(注:开发环境基于wampserver2.4)。

1)打开/config/主要保护。php配置文件,将下面这段urlManager代码的注释去掉:

& # 39;urlManager& # 39;,=祝辞,阵列(   ,,,& # 39;urlFormat& # 39;,=祝辞,& # 39;path & # 39;   ,,,& # 39;规则# 39;,=祝辞,阵列(   ,,,,,,,& # 39;& lt;控制器:\ w +祝辞/& lt; id: \ d +祝辞& # 39;=祝辞& # 39;& lt; controller>/视图# 39;   ,,,,,,,& # 39;& lt;控制器:\ w +祝辞/& lt;行动:\ w +祝辞/& lt; id: \ d +祝辞& # 39;=祝辞& # 39;& lt; controller>/& lt; action> & # 39;   ,,,,,,,& # 39;& lt;控制器:\ w +祝辞/& lt;行动:\ w +祝辞& # 39;=祝辞& # 39;& lt; controller>/& lt; action> & # 39;   ,,,),   ),

2)去掉以后,我们就可以使用类似http://yourdomain.com/index.php/controller/action这种形式的网址去访问应用,但是接下来我们还要隐藏掉中间的那个index . php,

相关文章教程推荐:yii教程

3)在应用的根目录下添加一个名为. htaccess的文件,并写入以下内容:

Options  + FollowSymLinks   IndexIgnore  */*   RewriteEngine    #,if  a  directory 或是a  file 存在,use  it 直接   RewriteCond  % {REQUEST_FILENAME} ! - f   RewriteCond  % {REQUEST_FILENAME} ! - d   #,otherwise  forward  it 用index . php   RewriteRule 只index . php

4)开启apache的重写模块,在httpd。会议中找到# LoadModule rewrite_module模块/mod_rewrite.so,把前面的“#”去掉;

5)重启apache;

6)继续编辑主要。php文件,在刚才那个urlManager的数组中添加一个元素:

& # 39;urlManager& # 39;,=祝辞,阵列(   ,,,& # 39;urlFormat& # 39;,=祝辞,& # 39;path & # 39;   ,,,& # 39;showScriptName& # 39;,=祝辞,假的,,//,添加这一行   ,,,& # 39;规则# 39;,=祝辞,阵列(   ,,,,,,,& # 39;& lt;控制器:\ w +祝辞/& lt; id: \ d +祝辞& # 39;=祝辞& # 39;& lt; controller>/视图# 39;   ,,,,,,,& # 39;& lt;控制器:\ w +祝辞/& lt;行动:\ w +祝辞/& lt; id: \ d +祝辞& # 39;=祝辞& # 39;& lt; controller>/& lt; action> & # 39;   ,,,,,,,& # 39;& lt;控制器:\ w +祝辞/& lt;行动:\ w +祝辞& # 39;=祝辞& # 39;& lt; controller>/& lt; action> & # 39;   ,,,),   ),

7)完成!

yii框架如何配置pathinfo的模式