偽靜態例子與APACHE偽靜態配置

來源:互聯網
上載者:User

標籤:style   http   io   color   ar   os   sp   strong   檔案   

偽靜態只是改變了URL的顯示形式,實際上還是網站頁面還是動態網頁面。偽靜態頁面尾碼可以是html 、 htm 或者是目錄格式等。那麼為什麼要用 偽靜態呢?

兩點原因:1是seo最佳化,偽靜態有利於搜尋引擎的收錄,能夠增加網站最佳化效果;2是url看起來簡單,網站URL給人專業性。

我們依然是通過.htaccess的檔案來實現偽靜態。具體的.htaccess設定詳見兩種apache網域名稱跳轉法簡單完成重新導向中的“2.用.htaccess做網域名稱跳轉”。

保證.htaccess檔案能用後,我們在.htaccess中增加相關內容實現偽靜態。下面是偽靜態例子,我同時在配置裡面#號部分給大家簡單說明幾類偽靜態作用。apache偽靜態配置代碼如下:

RewriteRule ^Article/nsort5-1\.html article_cat\.php\?id=20 [NC,QSA,L]
#當使用者訪問 http://www.sodone.com/Article/nsort5-1.html 時實際後台執行的是 http://www.sodone.com/article_cat\.php\?id=20
RewriteRule ^Article/nsort1-1\.html article_cat\.php\?id=16 [NC,QSA,L]
RewriteRule ^Article/nsort2-1\.html article_cat\.php\?id=17 [NC,QSA,L]
RewriteRule ^Article/nsort3-1\.html article_cat\.php\?id=18 [NC,QSA,L]
RewriteRule ^Article/nsort4-1\.html article_cat\.php\?id=19 [NC,QSA,L]

RewriteRule ^Article/Article-([0-9]+)\.html$ article\.php\?id=$1 [NC,QSA,L]
#當使用者訪問 http://www.sodone.com/Article/ARTICLE-101.html 時實際後台執行的是 http://www.sodone.com/article.php?id=101

RewriteRule ^help/help([0-9]+)\.html$ help\.php\?categorie_id=$1 [NC,QSA,L]
RewriteRule ^help/help([0-9]+)-([0-9]+)\.html$ help\.php\?id=$2&categorie_id=$1 [NC,QSA,L]
#當使用者訪問 http://www.sodone.com/help/help15-52.html 時實際後台執行的是 http://www.sodone.com/help.php?id=52&categorie_id=15
#注意 $1 與$2的關係,很多人在這裡出問題;在對前面部分的URL替換過程中先替換$1 ,然後替換$2

# direct one-word access
RewriteRule ^index\.html$ index\.php [L]
#當使用者訪問 http://www.sodone.com/index.html 時實際後台執行的是 http://www.sodone.com/index.html
RewriteRule ^category$ index\.php [L]
#當使用者訪問 http://www.sodone.com/category 時實際後台執行的是 http://www.sodone.com/index.html

對配置做幾點補充說明:
L 表明當前規則是最後一條規則,停止分析以後重寫
NC 不區分大小寫
QSA 追加請求的字串
^表示語句開始
$ 表示語句的結束

作者: sodone
著作權屬於: SoDone酥蛋

偽靜態例子與APACHE偽靜態配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.