php伪静态设置怎么写,php 伪静态 url重写简单示例

1、新建一个记事本文件,重命名为 .htaccess ,放到根目录中。

内容如下:

复制代码 代码示例:

RewriteEngine on

RewriteRule ^article/index.html$ article/index.php

RewriteRule ^article/detail-(.[0-9]*).html$ article/index.php?type=detail&id=$1

RewriteRule ^article/list-(.[0-9]*)-(.[0-9]*).html$ article/index.php?type=list&classid=$1&offset=$2

RewriteRule ^product/index.html$ product/index.php

RewriteRule ^product/detail-(.[0-9]*).html$ product/index.php?type=detail&id=$1

RewriteRule ^product/list-(.[0-9]*)-(.[0-9]*).html$ product/index.php?type=list&classid=$1&offset=$2

RewriteRule ^index.html$ index.php

RewriteRule ^aboutus/detail-(.[0-9]*).html$ aboutus/index.php?type=detail&id=$1

RewriteRule ^aboutus/detail-(.[0-9]*)-(.[0-9]*).html$ aboutus/index.php?type=list&classid=$1&offset=$2

说明:

aboutus、article、product是模块名。

复制代码 代码示例:

RewriteRule ^aboutus/detail-(.[0-9]*)-(.[0-9]*).html$ aboutus/index.php?type=list&classid=$1&offset=$2

这个是aboutus模块分页的。

RewriteRule ^index.html$ index.php 是首页伪静态重写

如果有哪个模块需要伪静态,都要参考上面的写进 .htaccess 文件里面。

2、到网站后台的系统管理——配置管理——需要伪静态的模块链接模式改为2即可,其他的不要改。

3、对上面地址重写后,需要修改链接地址,比如导航的链接地址,拿aboutus模块的第一个id的链接地址来讲怎么写成静态地址,上面的 aboutus/detail-(.[0-9]*).html ,这里的(.[0-9]*) 就改成1,修改成静态地址是这样 aboutus/detail-1.html 也可以自定义添加1个链接模式就可以了。

4、删除缓存,比如article 模块,首页的地址还是article目录,不用改,打开article模块,然后看到文章的链接都是静态的了。

注意:如果把.htaccess,放到根目录下出现网页打不开等错误,删除 .htaccess  网站可以正常打开,原因可能是环境不支持。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值