用Apache的rewrite產生偽靜態頁面

來源:互聯網
上載者:User

我們知道,搜尋引擎是偏愛靜態頁面的,因此,把諸如:http://www.jianglb.com/?p=123的頁面改成http://www.jianglb.com/apaeche-rewrite.html顯然有利於被搜尋.

但是,如果一般的直接用http://www.jianglb.com/apaeche-rewrite.html而又不存在這地址的檔案,就肯定會報錯檔案不存在.

這就要使用到Apache的rewrite模組,把這些URL重新導向某個動態程式如index.php,當然,index.php也需要有相應的程式識別這些地址,以從資料庫存取資料.

啟用rewrite,要確認apache設定檔:httpd.conf中有
LoadModule rewrite_module libexec/mod_rewrite.so

網站所在的目錄定義了下面的內
容:
Options Indexes FollowSymLinks
AllowOverride all

網站所在目錄還必須包括一個.htaccess
內容為:
rewriteengine on
rewritebase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

如此則URL請求自動發送到index.php了

 
 
我寫了個正值表達試是這樣的
RewriteRule   ^/*(.*?)/r_(.*?)-(.*?)-(.*?)-(.*?)-(.*?).html   $1/$2.php?type1=$3&type2=$4&type3=$5&page=$6    
偽靜態格式必須為r_xxx-變數1-變數2-變數3-變數4.html
有什麼正值運算式如果有一個變數就r_xxx-變數1.html
二個變數就r_xxx-變數1-變數2.html
三個變數就r_xxx-變數1-變數2-變數3.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.