您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php 伪静态 url重写简单示例

2025/7/15 15:34:43发布23次查看
rewriteengine onrewriterule ^article/index.html$ article/index.phprewriterule ^article/detail-(.[0-9]*).html$ article/index.php?type=detail&id=$1rewriterule ^article/list-(.[0-9]*)-(.[0-9]*).html$ article/index.php?type=list&classid=$1&offset=$2rewriterule ^product/index.html$ product/index.phprewriterule ^product/detail-(.[0-9]*).html$ product/index.php?type=detail&id=$1rewriterule ^product/list-(.[0-9]*)-(.[0-9]*).html$ product/index.php?type=list&classid=$1&offset=$2rewriterule ^index.html$ index.phprewriterule ^aboutus/detail-(.[0-9]*).html$ aboutus/index.php?type=detail&id=$1rewriterule ^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 网站可以正常打开,原因可能是环境不支持。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product