IIS7以上版本的空間配置偽靜態(tài)等內(nèi)容與IIS6與很大區(qū)別的,IIS6是在httpd.conf文件中寫配置規(guī)則,而IIS7則是在根目錄下的web.config文件中寫規(guī)則,而且寫法也大有不同。
如果你的網(wǎng)站已有web.config文件,則把以下規(guī)則直接寫在節(jié)點 中就可以,如果沒有web.config文件,需要在根目錄新建一個,內(nèi)容按照下面的完全復(fù)制即可,注意:所有配置規(guī)則都要寫在節(jié)點中。
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <rewrite> <rules> <rule name="301Redirectwww" stopProcessing="true"> <match url="(.*)"/> <conditions logicalGrouping="MatchAny"> <add input="{HTTP_HOST}" pattern="^zztuku\.com$"/> </conditions> <action type="Redirect" url="https://www.zztuku.com/{R:0}" redirectType="Permanent"/> </rule> </rules> </rewrite> </system.webServer> </configuration>
一、網(wǎng)站301重定向
<rule name="301Redirectwww" stopProcessing="true"> <match url="(.*)"/> <conditions logicalGrouping="MatchAny"> <add input="{HTTP_HOST}" pattern="^zztuku\.com$"/> </conditions> <action type="Redirect" url="https://www.zztuku.com/{R:0}" redirectType="Permanent"/> </rule>
要注意的是,所有規(guī)則的name名字不能一樣,這里的“301Redirectwww”可以自己隨意命名。這段代碼可以實現(xiàn)將不帶www的網(wǎng)址定向到帶www的,同理,其他域名跳轉(zhuǎn)把網(wǎng)址做相應(yīng)改變。
二、去index.html、index.php等后綴
<rule name="Redirectindex" stopProcessing="true"> <match url="^index.html"/> <conditions logicalGrouping="MatchAny"/> <action type="Redirect" url="https://www.zztuku.com/" redirectType="Permanent"/> </rule>
根據(jù)自己的需求,將要去掉的后綴名替換。
三、偽靜態(tài)規(guī)則
<rule name="Redirecttagsl" stopProcessing="true"> <match url="^tags/(\w+)/([0-9]+).html"/> <action type="Rewrite" url="tags.php?/{R:1}/{R:2}/"/> </rule>
1、偽靜態(tài)規(guī)則根據(jù)不同的網(wǎng)址形式有不同的寫法,只是提供一個參考,其中通配符與百度移動適配中提到的正則式相同,大家可以參考《百度優(yōu)化之移動適配代碼正則表達(dá)式適配》。
2、規(guī)則語句中,match語句中網(wǎng)址前不能加“/”:
<match url="^tags/(\w+)/([0-9]+).html"/>
網(wǎng)址tags前面的“/”沒有。
3、action語句中不能使用轉(zhuǎn)義符:
<action type="Rewrite" url="tags.php?/{R:1}/{R:2}/"/>
網(wǎng)址中特殊符號并不需要轉(zhuǎn)義。
4、偽靜態(tài)規(guī)則中, {R:1}、{R:2}中1、2等數(shù)字代表與目標(biāo)網(wǎng)址中的參數(shù)對應(yīng),第一個參數(shù)后面對應(yīng)要寫1,以此類推。