php htaccess 伪静态,.htaccess伪静态实例分享

利用.htaccess实现伪静态功能在web开发中应该是经常用到的,下面作者总结了一些比较常用的利用.htaccess实现伪静态的实例和大家分享。

(1)将 index.php 伪静态成为 index.html

RewriteRule ^index\.html$ index.php

(2)将 news/info.php?id=3  伪静态成为  news/info_3.html

RewriteRule ^news/info_([0-9]{1,})\.html$ news/info.php?id=$1

(3)将 index.php?class_id=2&id=3  伪静态成为 2-3.html

RewriteRule ([0-9]{1,})-([0-9]{1,})\.html$ index.php?class_id=$1&id=$2

([0-9]{1,})-([0-9]{1,})\.html$是规则,index.php?action=$1&id=$2是要替换的url格式,$1代表第一个括号匹配的值,$2代表第二个,如此类推。

(4)将 tag.php?tag=php教程 或者 tag.php?tag=程序员 伪静态成为 tag/php教程 和 tag/程序员

RewriteRule ^tag/(.*)$ tag.php?tag=$1

(5)设置 404 跳转

ErrorDocument 404 http://www.phpernote.com/404.html

(6)禁止直接访问web目录中的后缀名为 .bak .inc 的文件

order deny,allow

deny from all

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值