用URLRewriter重寫url


用url重新一般都是使用URLRewriter庫,基本上都是一些配置,在webconfig中

首先配置configuration節點

<configSections>
            <section name="RewriterConfig" type="URLRewriter.Config.RewriterConfigSerializerSectionHandler,URLRewriter" />
    </configSections>

<system.web>節點下配置httpHandlers和httpModules,二者配置其一即可

httpModules配置

    <httpModules>
            <add type="URLRewriter.ModuleRewriter, URLRewriter" name="ModuleRewriter" />
        </httpModules>

 

httpHandlers配置

    <httpHandlers>
            <add verb="*" path="/*/list/*" type="URLRewriter.RewriterFactoryHandler,URLRewriter" />
            <add verb="*" path="/group/*" type="URLRewriter.RewriterFactoryHandler,URLRewriter" />
        </httpHandlers>

     <remove verb = "* " path = "*.asmx " />
    <add verb = "* " path = "* " type = "URLRewriter.RewriterFactoryHandler, URLRewriter" />
     <add verb = "* " path = "*.html " type =" URLRewriter.RewriterFactoryHandler, URLRewriter " />

 

<system.webServer>節點下添加

<handlers>
            <add name="Rewriter" path="*" verb="*" modules="IsapiModule" scriptProcessor="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" resourceType="Unspecified" requireAccess="None"
preCondition="classicMode,runtimeVersionv4.0,bitness32" /> </handlers>

 

 

接下來就是寫規則了。在webconfig的configuration內部的最底部添加RewriterConfig節點,並寫規則

<!--url重寫規則-->
    <RewriterConfig>
        <Rules>
            <!--店鋪-->
            <RewriterRule>
                <LookFor>~/(.*)/list/(.*)</LookFor>
                <SendTo>~/group/itemlist.aspx?name=$1&amp;keyword=$2</SendTo>
            </RewriterRule>
            <RewriterRule>
                <LookFor>~/group/(.*)</LookFor>
                <SendTo>~/group/circle.aspx?name=$1</SendTo>
            </RewriterRule>
        </Rules>
    </RewriterConfig>

 

 

這些基本上已經好了。但發布到iis上還需配置一些東西。即處理映射

選擇你發布的網站。選擇"處理程序映射"

 

然后:

選擇路徑:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll

保存即可。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM