Home Backend Development PHP Tutorial .htaccess伪静态实例

.htaccess伪静态实例

Jun 05, 2016 am 11:57 AM
auto background height important

利用.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;"&gt;FilesMatch "\.(bak|inc)$"&gt;  
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;"&gt;FilesMatch&gt;
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to use CSS to achieve the rotating background animation effect of elements How to use CSS to achieve the rotating background animation effect of elements Nov 21, 2023 am 09:05 AM

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

What does important in css mean? What does important in css mean? Aug 31, 2022 pm 06:24 PM

What does important in css mean?

Porsche leak suggests EV Boxster, Cayman could replace petrol models as soon as October 2025 Porsche leak suggests EV Boxster, Cayman could replace petrol models as soon as October 2025 Jun 15, 2024 pm 04:02 PM

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

Detailed explanation of CSS dimension properties: height and width Detailed explanation of CSS dimension properties: height and width Oct 21, 2023 pm 12:42 PM

Detailed explanation of CSS dimension properties: height and width

What coin is AUTO? What coin is AUTO? Feb 22, 2024 pm 09:40 PM

What coin is AUTO?

How to remove the height attribute of an element in jQuery? How to remove the height attribute of an element in jQuery? Feb 27, 2024 pm 01:24 PM

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

jQuery quickly removes the height attribute of an element jQuery quickly removes the height attribute of an element Feb 27, 2024 pm 02:09 PM

jQuery quickly removes the height attribute of an element

Different storage classes in C language Different storage classes in C language Sep 15, 2023 am 11:45 AM

Different storage classes in C language

See all articles