当前位置:Gxlcms > PHP教程 > php伪静态url重写简单示例

php伪静态url重写简单示例

时间:2021-07-01 10:21:17 帮助过:5人阅读

  1. RewriteEngine on
  2. RewriteRule ^article/index.html$ article/index.php
  3. RewriteRule ^article/detail-(.[0-9]*).html$ article/index.php?type=detail&id=$1
  4. RewriteRule ^article/list-(.[0-9]*)-(.[0-9]*).html$ article/index.php?type=list&classid=$1&offset=$2
  5. RewriteRule ^product/index.html$ product/index.php
  6. RewriteRule ^product/detail-(.[0-9]*).html$ product/index.php?type=detail&id=$1
  7. RewriteRule ^product/list-(.[0-9]*)-(.[0-9]*).html$ product/index.php?type=list&classid=$1&offset=$2
  8. RewriteRule ^index.html$ index.php
  9. RewriteRule ^aboutus/detail-(.[0-9]*).html$ aboutus/index.php?type=detail&id=$1
  10. RewriteRule ^aboutus/detail-(.[0-9]*)-(.[0-9]*).html$ aboutus/index.php?type=list&classid=$1&offset=$2

说明: aboutus、article、product是模块名。

  1. 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 网站可以正常打开,原因可能是环境不支持。

人气教程排行