.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 的文件

<FilesMatch "\.(bak|inc)$">   
    order deny,allow   
    deny from all   
</FilesMatch>
打赏

本文固定链接: https://www.cxy163.net/archives/4054 | 绝缘体

该日志由 绝缘体.. 于 2013年05月23日 发表在 未分类 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: .htaccess伪静态实例分享 | 绝缘体
关键字: , , , ,

.htaccess伪静态实例分享:等您坐沙发呢!

发表评论


快捷键:Ctrl+Enter