php偽靜態規則的書寫詳解

2021-09-01 08:58:58 字數 1975 閱讀 3812

這裡以阿帕奇為伺服器軟體,直接上案例:

1.把index.html重定向到index.php

rewriteengine on

options -indexesrewriterule ^index.html$  /index.php  [nc]

效果:訪問www.test.com/index.html效果等於www.test.com/index.php

2.把index重定向到index.php

rewriteengine on

options -indexesrewriterule ^index$  /index.php  [nc]

效果:訪問www.test.com/index效果等於www.test.com/index.php

3.根目錄下的php檔案,用html字尾也能訪問

寫法1:

rewriteengine on

options -indexes

rewriterule ^([a-za-z0-9_])\.html$  /$1.php  [nc]

效果:訪問www.test.com/index.html效果等於www.test.com/index.php

訪問www.test.com/abc.html效果等於www.test.com/abc.php

4.根目錄下的php檔案,直接訪問檔名效果一樣

rewriteengine on

options -indexes

rewriterule ^([a-za-z0-9_])$  /$1.php  [nc]

效果:訪問www.test.com/index效果等於www.test.com/index.php

訪問www.test.com/abc效果等於www.test.com/abc.php

5.訪問檔名+html效果等效字尾為php的檔案

rewriteengine on

options -indexes

rewriterule ^/?([a-z/]+)\.html$$1.php [nc]

效果:   

訪問www.test.com/index.html效果等於www.test.com/index.php

訪問www.test.com/abc/abc.html效果等於www.test.com/abc/abc.php

6.訪問所有目錄下的檔案等效於訪問檔名+字尾

rewriteengine on

options -indexes

rewriterule ^/?([a-z/]+)$$1.php [nc]

效果:訪問www.test.com/index效果等於www.test.com/index.php

訪問www.test.com/abc/abc效果等於www.test.com/abc/abc.php

7.404頁面跳轉設定

rewriteengine on

options -indexes

errordocument 404 /404.html

PHP 偽靜態規則 寫法

偽靜態是相對真實靜態來講的,通常我們為了增強 搜尋引擎 的友好面,都將文章內容生成靜態頁面,但是有的朋友為了實時的顯示一些資訊。或者還想運用動態指令碼解決一些問題。不能用靜態的方式來展示 內容。但是這就損失了對搜尋引擎的友好面。怎麼樣在兩者之間找個中間方法呢,這就產生了偽靜態技術。就是展示出來的是以...

PHP專案 偽靜態規則

2016年03月30日 16 53 59 偽靜態實際上是利用php把當前位址解析成另一種方法來訪問 要學偽靜態規則的寫法,要懂一點正則 一 正規表示式教程 有乙個經典的教程 正規表示式30分鐘入門教程 常用正則如下 換行符以外的所有字元 w 匹配字母或數字或下劃線或漢字 s 匹配任意的空白符 d 匹...

偽靜態規則RewriteRule htaccess

一 正規表示式教程 偽靜態規則寫法rewriterule htaccess詳細語法使用教程分享 簡單說下 偽靜態實際上是利用php把當前位址解析成另外一種方法進行訪問 要學偽靜態規則的寫法,你必須得懂一點正則,不會沒關係,照著下面的套就行 一 正規表示式教程 有乙個經典的教程 正規表示式30分鐘入門...