近幾天公司里開(kāi)發(fā)的項(xiàng)目有幾個(gè)運(yùn)行在IIS7.5上,由于全站采用的是偽靜態(tài),因此從網(wǎng)上找到兩兩種方法來(lái)實(shí)現(xiàn)。這兩種方法各有優(yōu)勢(shì):第一種比較靈活,只要把文件拷到根目錄下,即可直接顯示所有偽靜態(tài)頁(yè)面(適用于此偽靜態(tài)規(guī)則的所有項(xiàng)目,如ThinkPHP),無(wú)需更改代碼;第二種適合有子目錄時(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
代碼如下:
<?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>
新聞熱點(diǎn)
疑難解答
圖片精選