win7/Win8/Win10, IIS7.5/IIS8/IIS10 配置僞靜態

第一步: 
從以下地址中下載URLRewriter組件組件:

官方下載地址:http://download.microsoft.com/download/0/4/6/0463611e-a3f9-490d-a08c-877a83b797cf/MSDNURLRewriting.msi

第二步:在網站項目中添加URLRewriter程序集的引用。

第三步:配置webconfig文件:css

注意事項:一、參數用()括起來,使用 $1 來得到參數。二、多個參數的時候使用&分割。html

    1。在<configuration>與</configuration>節點中間加入以下配置:web

<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>

    或者api

<system.web>                         
   <httpModules>                          
    <add type=」URLRewriter.ModuleRewriter, URLRewriter」 name=」ModuleRewriter」/>                       
   </httpModules>                         
  </system.web>                                                                                   

  

3。配置僞靜態的語法:在<configuration>與</configuration>之間加入<RewriterConfig> </RewriterConfig>節點。  asp.net

    在  <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>網站

例子如:url

複製代碼
    <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&amp;price=$2</SendTo>
            </RewriterRule>
         <RewriterRule>
                <LookFor>/shop/list-(.*)-(.*)-(.*).html</LookFor>
                <SendTo>/shop/list.aspx?nav=$1&amp;licno=$2&amp;orderby=$3</SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>/shop/list-(.*)-(.*)-(.*)-(.*).html</LookFor>
                <SendTo>/shop/list.aspx?nav=$1&amp;licno=$2&amp;orderby=$3&amp;price=$4</SendTo>
            </RewriterRule>
        </Rules>
    </RewriterConfig>
複製代碼

或者spa

<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>

url是可使用正則表達式的。好比上面的例子:.net

規則一:當發現文件類型爲   .gif, .png,.jpg, .ico, .pdf, .css or .js時,中止rewrite

規則二:就是將/lmh重寫到/Users.aspx?user=lmh,$在正則表達式中表示是串的結束,也就是說/lmhe是不會被重寫到to後的地址的,若是把$去掉則能夠

規則三:將tags/xxx重寫爲tag/tagcloud.aspx?Tag=xxx

規則四:當用戶輸入錯誤象mypagexxx形式的地址時,轉到網站默認頁面

規則五:設置用戶網站的默認頁面爲index.htm

新添asp規則:將article.asp?id=13&sid=10&page=2經過僞靜態轉換成article-10-13-2.html格式來訪問頁面

第四步:配置IIS7.5 或IIS7.0

1.新建一個應用程序池:名稱:任意如:aspnet;選擇net 
FrameWork版本(若是你的網站時候2.0的話就選擇2.0,個人是4.0)在此我選擇Net FramWork v 4.030319. 
託管管道模式先暫時設置爲集成模式。等下面的設置完成以後再將託管管道模式設置爲經典模式。若是下面的設置完成以後不把應用程序設置爲經典模式的話,僞靜態的功能能夠實現,可是頁面的樣式圖片不能正常顯示這是設置的關鍵。

2 新建一個網站 website ,將此站點的應用程序程序池設置爲aspnet。

3 選中你的站點好比website ,而且切換到功能視圖。雙擊【處理程序映射】在打開窗口右側的操做欄目下作以下操做。

   3.1,【添加腳本映射】-路徑爲:*.html.可執行文件爲:C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll 
    注意:若是你的網站是2.0。可執行文件爲:C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll 。名稱:任意,好比:html.
   3.2, 【添加通配符腳本映射】 請求路徑爲*。可執行文件爲:C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_isapi.dll,名稱任意,好比:aspnet.
   3.3,【託管處理程序映射】(路徑:* 可執行文件:System.Web.UI.PageHandlerFactory 名稱 任意 好比Html-Integrate)
   3.4, 雙擊website站點切換到站點功能視圖。而後雙擊模塊,打開窗口以後在右側的操做欄目下面,單擊【添加託管模塊】-》名稱:任意 如aspnet 類型:URLRewriter.ModuleRewriter 而且 把【僅針對向asp.net 應用程序 或託管處理程序發出請求調用】前面的選項 勾上。(記住必定要勾上)。
   3.5 最後一步:雙擊iis7.0或7.5的應用程序池。在應用程序池列表中找到【aspnet】應用程序池。雙擊打開以後。將aspnet應用程序池的【託管管道模式】設置爲經典模式。

 

轉載自 http://www.cnblogs.com/luckly-hf/archive/2013/03/07/2947687.html

相關文章
相關標籤/搜索