YII 框架 第十天(1) urlManager 地址美化

来源:互联网 发布:英语软件哪个比较好 编辑:程序博客网 时间:2024/05/20 08:41

1.给页面添加.html后缀(伪静态),有利于搜索引擎优化


源地址: http://localhost/cms/index.php?r=goods/category

美化后 http://localhost/cms/index.php/goods/category.html


方法

2.美化GET传值方式

源地址:http://localhost/cms/index.php?r=goods/detail&id=8

美化后:http://localhost/cms/index.php/goods/8.html


方法

 'goods/<id:\d+>'=>array('goods/detail','urlSuffix'=>'.html'),

3:不显示index.php

这个需要到服务器配置,和php没有关系

涉及到apache的重写


首先卡其 rewrite 模块 并重启服务器



2.新建文本文件,写入

RewriteEngine on


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d


RewriteRule . index.php


然后 另存为到网站的根目录下,命名为 .htaccess  

在windows下是创建以 点 开头的文件的,只有另存为方式可以


之后访问

源地址:http://localhost/cms/index.php/goods/8.html

美化后:http://localhost/cms/goods/20.html

原创粉丝点击