apache 僞靜態 .htaccess

雖然網上有不少教程,可是我在這裏進行簡單對我用到的總結一下。php

加載Rewrite模塊:html

在conf目錄下httpd.conf中找到網站

LoadModule rewrite_module modules/mod_rewrite.so

這句,去掉前邊的註釋符號「#」,或添加這句。spa

.htacess文件,開頭內容以下:設計

RewriteEngine oncode

RewriteEngine on是表明開啓rewrite。在正是寫規則前,先爲你們講一下重寫中設計到的特殊字符的含義。和普通正則是通用的!htm

*表明前面0或更多個字符blog

+表明前面1或更多個字符教程

?表明前面0或1個字符字符串

^表明字符串的開始位置

$表明字符串結束的位置

.爲通配符,表明任何字符

\將跟在其後的字符還原爲字符自己,例如「\+」表明的就是「+」,而非其它意思。

^在方括號裏表示非的意思。例如[^.]表明非通配符。

在這裏,我給你們列出一個我用到的.htacess。

RewriteEngine on
RewriteRule index.htm$  dashboard.php
RewriteRule ing-([0-9]{1,}).html$ activity_ing.php?page=$1
RewriteRule ago-([0-9]{1,}).html$ activity_ago.php?page=$1
RewriteRule mine-([0-9]{1,}).html$ activity_mine.php?page=$1
RewriteRule den-([0-9]{1,}).html$ dentify.php?page=$1
RewriteRule after-([0-9]{1,}).html$ after_activity.php?page=$1
RewriteRule news-([0-9]{1,}).html$ news.php?article_id=$1
RewriteRule new-([0-9]{1,}).html$ news_after.php?article_id=$1
RewriteRule yijian.html$ yijian.php
RewriteRule byebye.html$ byebye.php

若是網站作改版,致使URL結構發生了變化,怎麼辦?

答案很簡單,咱們能夠利用.htacess文件,經過寫rewrite規則,將老的URL 301到新的URL上。

 

 

 

轉載請註明出處:http://www.cnblogs.com/yydcdut/p/3688346.html

相關文章
相關標籤/搜索