第一步:在網站項目漲添加URLRewriter程序集的引用和FormRewriterControlAdapter程序集引用。
注:如果項目中有分頁,那么需要添加“FormRewriterControlAdapter”程序集引用,否則不需要添加該引用。
下載地址:http://www.net.cn/service/ziliao/cpsc/200906/3842.html(萬網/幫助中心(M享主機UrlRewrite組件和使用手冊))
第二步:配置webconfig文件:
注意事項:1、參數用()括起來,使用 $1 來獲得參數。2、多個參數的時候使用&分割。
1、在<configuration>與</configuration>節點中間加入如下配置:
代碼如下:
<configSections>
<section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
</configSections>
2、在<system.web>與</system.web> 之間加入
代碼如下:
<httpHandlers>
<add verb="*" path="*.aspx" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
<add verb="*" path="*.html" type="URLRewriter.RewriterFactoryHandler, URLRewriter" />
</httpHandlers>
或者
代碼如下:
<system.web>
<httpModules>
<add type=”URLRewriter.ModuleRewriter, URLRewriter” name=”ModuleRewriter”/>
</httpModules>
</system.web>
3、配置偽靜態的語法:在<configuration>與</configuration>之間加入<RewriterConfig> </RewriterConfig>節點。
在<RewriterConfig>與</RewriterConfig>之間加入偽靜態規則:
<Rules> <!–定義偽靜態第一條規則開始–> <RewriterRule> <LookFor>~/xxxx/view(.[/d]*)/.html</LookFor> <SendTo>~/xxxx/view.aspx?id=$1</SendTo> </RewriterRule>
<!–定義偽靜態第一條規則結束–> <!–定義偽靜態第二條規則開始–> <RewriterRule> <LookFor>~/yyyy/(.[/d]*)/view.html</LookFor> <SendTo>~/yyyy/view.aspx?id=$1</SendTo> </RewriterRule>
例子如:
代碼如下:
<RewriterConfig>
<Rules>
<!--官網-->
<RewriterRule>
<LookFor>~/web/new/type-(.[0-9]*)/.html</LookFor>
<SendTo>~/web/new.aspx?id=$1</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>/index.html</LookFor>
<SendTo>/index.aspx</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>/aboutus/aboutusContent-(.*).html</LookFor>
<SendTo>/aboutus/aboutusContent.aspx?pageurl=$1</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>/shop/GiftList-(.*)-(.*).html</LookFor>
<SendTo>/shop/GiftList.aspx?nav=$1&price=$2</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>/shop/list-(.*)-(.*)-(.*).html</LookFor>
新聞熱點
疑難解答
圖片精選