.htaccess伪静态实例
Jun 05, 2016 am 11:57 AM利用.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
1
|
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/程序员
1
|
RewriteRule ^tag/(.*)$ tag.php?tag=$1
|
(5)设置 404 跳转
ErrorDocument 404 http://www.phpernote.com/404.html
(6)禁止直接访问web目录中的后缀名为 .bak .inc 的文件
1
|
<code class="keyword" style="margin:0px !important;padding:0px !important;outline:0px !important;float:none !important;vertical-align:baseline !important;position:static !important;left:auto !important;top:auto !important;right:auto !important;bottom:auto !important;height:auto !important;width:auto !important;line-height:1.1em !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;font-size:1em !important;min-height:auto !important;color:#006699 !important;background:none !important;">FilesMatch "\.(bak|inc)$">
|
2
|
order deny,allow
|
3
|
deny from all
|
4
|
<code class="keyword" style="margin:0px !important;padding:0px !important;outline:0px !important;float:none !important;vertical-align:baseline !important;position:static !important;left:auto !important;top:auto !important;right:auto !important;bottom:auto !important;height:auto !important;width:auto !important;line-height:1.1em !important;font-family:Consolas, 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace !important;font-weight:bold !important;font-size:1em !important;min-height:auto !important;color:#006699 !important;background:none !important;">FilesMatch>
|

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to use CSS to achieve the rotating background animation effect of elements

Porsche leak suggests EV Boxster, Cayman could replace petrol models as soon as October 2025

Detailed explanation of CSS dimension properties: height and width

How to remove the height attribute of an element in jQuery?

jQuery quickly removes the height attribute of an element

Different storage classes in C language
