IIS7.5使用web.config設置偽靜態(tài)的二種方法
近幾天公司里開發(fā)的項目有幾個運行在IIS7.5上,由于全站采用的是偽靜態(tài),因此從網(wǎng)上找到兩兩種方法來實現(xiàn)。這兩種方法各有優(yōu)勢:第一種比較靈活,只要把文件拷到根目錄下,即可直接顯示所有偽靜態(tài)頁面(適用于此偽靜態(tài)規(guī)則的所有項目,如ThinkPHP),無需更改代碼;第二種適合有子目錄時的偽靜態(tài),比如一個網(wǎng)站下有多個子網(wǎng)站且都要使用偽靜態(tài),那么就考慮使用第二種方法了,第一種會報錯誤。兩種方法,自己根據(jù)情況使用吧(當然,并不是適用所有項目,可以根據(jù)項目的偽靜態(tài)規(guī)則自行調整)。以下是代碼:
第一種方法:web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="OrgPage" stopProcessing="true">
<match url="^(.*)$" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_HOST}" pattern="^(.*)$" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
第二種方法:web.config
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="規(guī)則 1" stopProcessing="true">
<match url="^includes/(.*)" />
<action type="Rewrite" url="includes\/{R:1}" />
</rule>
<rule name="規(guī)則 2" stopProcessing="true">
<match url="^(blog)/includes/(.*)" />
<action type="Rewrite" url="{R:1}/includes\/{R:2}" />
</rule>
<rule name="規(guī)則 3" stopProcessing="true">
<match url="^(blog)/(.*).html(.*)" />
<action type="Rewrite" url="{R:1}/index.php\/{R:2}.html{R:3}" />
</rule>
<rule name="規(guī)則 4" stopProcessing="true">
<match url="^(.*).html(.*)" />
<action type="Rewrite" url="index.php\/{R:1}.html{R:2}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
下面是補充:
IIS 7和IIS 7.5及以后的版本估計都會使用web.config來實現(xiàn)偽靜態(tài)規(guī)則,于是我們以前的偽靜態(tài)文件必須更改。網(wǎng)上找了一圈,還沒有發(fā)現(xiàn)比較全面的web.config偽靜態(tài)規(guī)則,于是我們這里整理一份,供初次使用的朋友參考。
實現(xiàn)普通頁面、帶一個數(shù)字參數(shù)頁面和帶兩個參數(shù)頁面的偽靜態(tài)!
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Index" stopProcessing="true">
<match url="^index.html" />
<action type="Rewrite" url="index.php" />
</rule>
<rule name="Rule1" stopProcessing="true">
<match url="^news_([0-9]+).html" />
<action type="Rewrite" url="news.php?nid={R:1}" />
</rule>
<rule name="Rule2" stopProcessing="true">
<match url="news_list_([0-9]+)_([0-9]+).html" />
<action type="Rewrite" url="news_list.php?nid={R:1}&page={R:2}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
IIS 7.5通過web.config實現(xiàn)301重定向的方法,將不帶www的域名轉向到帶www的域名上!
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Redirect" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^chuangluo.com$" />
</conditions>
<action type="Redirect" url="http://www.chuangluo.com/{R:0}" redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
由于我們的網(wǎng)站使用了轉義字符,因此在實際使用的時候,大家不可以直接復制以上代碼。請復制粘貼到Dreamweaver等編輯器后,使用替換功能把雙引號全部替換為英文狀態(tài)下的雙引號,然后再修改rule標簽內(nèi)的內(nèi)容就可以了,跳轉的地方請更改為自己的網(wǎng)址即可。
需要注意的地方是以前httpd.ini和.htaccess支持網(wǎng)址中兩個參數(shù)用&符號鏈接,在web.config中是不支持的,需要將這個符號更改為&才能正常使用。由于我們目前只有一臺這種類型的服務器使用經(jīng)驗,有可能存在不足,如有更多更全面的資料,歡迎交流學習!
相關文章
WIN10安裝有多種數(shù)據(jù)庫時如何防止電腦卡慢問題
這篇文章主要介紹了WIN10安裝有多種數(shù)據(jù)庫時如何防止電腦卡慢問題,本文圖文并茂給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-11-11
Wins2003系統(tǒng)中Apache性能優(yōu)化方法
為了滿足網(wǎng)站高負荷的要求,在調整Apache參數(shù)時發(fā)現(xiàn)進程經(jīng)常占用內(nèi)存過多導致當機。經(jīng)過不斷的優(yōu)化和修改參數(shù)組合,終于讓服務器穩(wěn)定 下來,可以滿足大量訪問的考驗和應用要求2012-12-12
阿里云Windows 2008一鍵安裝包配置php web環(huán)境圖文安裝教程(IIS+Php+Mysql)
這篇文章主要介紹了阿里云Windows 2008一鍵安裝包配置web環(huán)境圖文安裝教程(IIS+Php+Mysql),當前使用2008 r2的朋友越來越多了,這個安裝包對于快速架設php運行環(huán)境是非常不錯的工具2016-10-10
Windows Defender防火墻無法更改某些設置,錯誤代碼0x80070422的解決方法
事情是這樣的,本人不小心手欠按到了破解器上面的一鍵禁止Windows defenders的按鈕,導致我的防火墻整個被禁止掉了,進服務頁面里面也無法開啟2024-05-05
在windows操作系統(tǒng)中查詢端口占用和清除端口占用的程序
這篇文章主要介紹了在windows操作系統(tǒng)中,查詢端口占用和清除端口占用的程序,需要的朋友可以參考下2019-09-09
IIS7 多域名綁定同一物理目錄不同默認文檔的實現(xiàn)方法
這篇文章主要介紹了IIS7多域名綁定同一物理目錄,設置不同默認文檔的解決方案,需要的朋友可以參考下2017-04-04
Microsoft?iis服務器安裝ssl證書(https)的簡單方法
這篇文章主要介紹了Microsoft?iis服務器安裝ssl證書的簡單方法,需要的朋友可以參考下2022-10-10

