近幾天公司里開發的項目有幾個運行在IIS7.5上,由于全站采用的是偽靜態,因此從網上找到兩兩種方法來實現。這兩種方法各有優勢:第一種比較靈活,只要把文件拷到根目錄下,即可直接顯示所有偽靜態頁面(適用于此偽靜態規則的所有項目,如ThinkPHP),無需更改代碼;第二種適合有子目錄時的偽靜態,比如一個網站下有多個子網站且都要使用偽靜態,那么就考慮使用第二種方法了,第一種會報錯誤。兩種方法,自己根據情況使用吧(當然,并不是適用所有項目,可以根據項目的偽靜態規則自行調整)。以下是代碼:
第一種方法: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="規則 1" stopProcessing="true">
<match url="^includes/(.*)" />
<action type="Rewrite" url="includes//{R:1}" />
</rule>
<rule name="規則 2" stopProcessing="true">
<match url="^(blog)/includes/(.*)" />
<action type="Rewrite" url="{R:1}/includes//{R:2}" />
</rule>
新聞熱點
疑難解答
圖片精選