第一步:在網(wǎng)站項目漲添加URLRewriter程序集的引用和FormRewriterControlAdapter程序集引用。
注:如果項目中有分頁,那么需要添加“FormRewriterControlAdapter”程序集引用,否則不需要添加該引用。
下載地址:(萬網(wǎng)/幫助中心(M享主機UrlRewrite組件和使用手冊))
第二步:配置webconfig文件:
注意事項:1、參數(shù)用()括起來,使用 $1 來獲得參數(shù)。2、多個參數(shù)的時候使用&分割。
1、在<configuration>與</configuration>節(jié)點中間加入如下配置:
復制代碼 代碼如下:
<configSections>
<section type="URLRewriter.Config.RewriterConfigSerializerSectionHandler, URLRewriter" />
</configSections>
復制代碼 代碼如下:
<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>
在<RewriterConfig>與</RewriterConfig>之間加入偽靜態(tài)規(guī)則:
<Rules> <!–定義偽靜態(tài)第一條規(guī)則開始–> <RewriterRule> <LookFor>~/xxxx/view(.[/d]*)/.html</LookFor> <SendTo>~/xxxx/view.aspx?id=$1</SendTo> </RewriterRule>
<!–定義偽靜態(tài)第一條規(guī)則結(jié)束–> <!–定義偽靜態(tài)第二條規(guī)則開始–> <RewriterRule> <LookFor>~/yyyy/(.[/d]*)/view.html</LookFor> <SendTo>~/yyyy/view.aspx?id=$1</SendTo> </RewriterRule>
例子如:
復制代碼 代碼如下:
<RewriterConfig>
<Rules>
<!--官網(wǎng)-->
<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>
<SendTo>/shop/list.aspx?nav=$1&licno=$2&orderby=$3</SendTo>
</RewriterRule>
<RewriterRule>
<LookFor>/shop/list-(.*)-(.*)-(.*)-(.*).html</LookFor>
<SendTo>/shop/list.aspx?nav=$1&licno=$2&orderby=$3&price=$4</SendTo>
</RewriterRule>
</Rules>
</RewriterConfig>
復制代碼 代碼如下:
<RewriterConfig>
<rewriter>
<rewrite url="^(/.+(/.gif|/.png|/.jpg|/.ico|/.pdf|/.css|/.js)(/?.+)?)$" to="$1" processing="stop" />
<rewrite url="~/lmh$" to="~/Users.aspx?user=lmh" processing="stop" />
<rewrite url="~/tags/(.+)" to="~/tag/tagcloud.aspx?tag=$1" processing="stop"/> <rewrite url="^~/mypage(/?.+)?$" to="~/index.htm$1" processing="stop" /> <rewrite url="~/article-([^-]+)-([^-]+)-([^-]+).html" to="~/testurl/article.asp?id=$1&sid=$2&page=$3" processing="stop"/>
<rewrite url="^(.*)/(/?.+)?$" to="$1/index.htm$2?" />
</rewritr>
</RewriterConfig>
規(guī)則一:當發(fā)現(xiàn)文件類型為 .gif, .png,.jpg, .ico, .pdf, .css or .js時,停止rewrite
規(guī)則二:就是將/lmh重寫到/Users.aspx?user=lmh,$在正則表達式中表示是串的結(jié)束,也就是說/lmhe是不會被重寫到to后的地址的,如果把$去掉則可以
規(guī)則三:將tags/xxx重寫為tag/tagcloud.aspx?Tag=xxx
規(guī)則四:當用戶輸入錯誤象mypagexxx形式的地址時,轉(zhuǎn)到網(wǎng)站默認頁面
規(guī)則五:設置用戶網(wǎng)站的默認頁面為index.htm
新添asp規(guī)則:將article.asp?id=13&sid=10&page=2通過偽靜態(tài)轉(zhuǎn)換成article-10-13-2.html格式來訪問頁面
第三步:配置IIS6.0
1、右鍵點擊 要設置網(wǎng)站的網(wǎng)站
2、屬性 ——》主目錄 ——》配置——》
3、如右側(cè)窗口,找到 .aspx 擴展名——》編輯——》復制 可執(zhí)行文件的路徑——》關(guān)閉
4、點擊 添加——》粘貼 剛復制的 可執(zhí)行文件路徑
5、擴展名填寫 .html (如果是 .htm 或者 任意你想要的擴展都可以 前提是以后的應用程序擴展列表里邊沒有該擴展)
6、不選中 確認文件是否存在
7、確定
新聞熱點
疑難解答
圖片精選