Centos下讓nginx支援.htaccess檔案實現偽靜態方法

來源:互聯網
上載者:User


Centos下讓nginx支援.htaccess檔案實現偽靜態方法 在Google上搜尋的資料很多人都說nginx目前不支援.htaccess檔案,我按照nginx的規則實驗了一下,結果發現 nginx是完全支援.htaccess檔案的!方法如下:1. 在需要使用.htaccess檔案的目錄下建立一個.htaccess檔案,如我的一個Discuz論壇目錄:vi /var/www/html/bbs/.htaccess  www.2cto.com  2. 在裡面輸入規則,我這裡輸入Discuz的偽靜態規則: # nginx rewrite rulerewrite ^(.*)/archiver/((fid|tid)-[w-]+.html)$ $1/archiver/index.php?$2 last;rewrite ^(.*)/forum-([0-9]+)-([0-9]+).html$ $1/forumdisplay.php?fid=$2&page=$3 last;rewrite ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+).html$ $1/viewthread.php?tid=$2&extra=page%3D$4&page=$3 last; rewrite ^(.*)/profile-(username|uid)-(.+).html$ $1/viewpro.php?$2=$3 last;rewrite ^(.*)/space-(username|uid)-(.+).html$ $1/space.php?$2=$3 last;rewrite ^(.*)/tag-(.+).html$ $1/tag.php?name=$2 last;# end nginx rewrite rulewq儲存退出。 3. 修改nginx設定檔:  www.2cto.com  vi /etc/nginx/nginx.conf4. 在需要添加偽靜態虛擬機器主機的server{}中引入.htaccess檔案, include /var/www/html/bbs/.htaccessinclude /var/www/html/bbs/.htaccess;(把這個改成你.htaccess檔案的具體位置)wq儲存退出。5. 重新載入nginx設定檔:/etc/init.d/nginx reload重新開啟網頁看看,如果偽靜態正常就證明你的rewrite rule文法是正確的。

聯繫我們

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