亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

IIS7.5使用web.config設(shè)置偽靜態(tài)的二種方法

 更新時(shí)間:2013年11月07日 15:41:50   投稿:zxhpj  
IIS7.5使用web.config設(shè)置偽靜態(tài)方法

近幾天公司里開發(fā)的項(xiàng)目有幾個(gè)運(yùn)行在IIS7.5上,由于全站采用的是偽靜態(tài),因此從網(wǎng)上找到兩兩種方法來實(shí)現(xiàn)。這兩種方法各有優(yōu)勢:第一種比較靈活,只要把文件拷到根目錄下,即可直接顯示所有偽靜態(tài)頁面(適用于此偽靜態(tài)規(guī)則的所有項(xiàng)目,如ThinkPHP),無需更改代碼;第二種適合有子目錄時(shí)的偽靜態(tài),比如一個(gè)網(wǎng)站下有多個(gè)子網(wǎng)站且都要使用偽靜態(tài),那么就考慮使用第二種方法了,第一種會(huì)報(bào)錯(cuò)誤。兩種方法,自己根據(jù)情況使用吧(當(dāng)然,并不是適用所有項(xiàng)目,可以根據(jù)項(xiàng)目的偽靜態(tài)規(guī)則自行調(diào)整)。以下是代碼:

第一種方法:web.config

復(fù)制代碼 代碼如下:

<?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

復(fù)制代碼 代碼如下:

<?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>

下面是補(bǔ)充:

IIS 7和IIS 7.5及以后的版本估計(jì)都會(huì)使用web.config來實(shí)現(xiàn)偽靜態(tài)規(guī)則,于是我們以前的偽靜態(tài)文件必須更改。網(wǎng)上找了一圈,還沒有發(fā)現(xiàn)比較全面的web.config偽靜態(tài)規(guī)則,于是我們這里整理一份,供初次使用的朋友參考。

實(shí)現(xiàn)普通頁面、帶一個(gè)數(shù)字參數(shù)頁面和帶兩個(gè)參數(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}&amp;page={R:2}" />
</rule>

</rules>
</rewrite>
</system.webServer>
</configuration>

IIS 7.5通過web.config實(shí)現(xiàn)301重定向的方法,將不帶www的域名轉(zhuǎn)向到帶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)站使用了轉(zhuǎn)義字符,因此在實(shí)際使用的時(shí)候,大家不可以直接復(fù)制以上代碼。請(qǐng)復(fù)制粘貼到Dreamweaver等編輯器后,使用替換功能把雙引號(hào)全部替換為英文狀態(tài)下的雙引號(hào),然后再修改rule標(biāo)簽內(nèi)的內(nèi)容就可以了,跳轉(zhuǎn)的地方請(qǐng)更改為自己的網(wǎng)址即可。

需要注意的地方是以前httpd.ini和.htaccess支持網(wǎng)址中兩個(gè)參數(shù)用&符號(hào)鏈接,在web.config中是不支持的,需要將這個(gè)符號(hào)更改為&才能正常使用。由于我們目前只有一臺(tái)這種類型的服務(wù)器使用經(jīng)驗(yàn),有可能存在不足,如有更多更全面的資料,歡迎交流學(xué)習(xí)!

相關(guān)文章

最新評(píng)論