18 1 月 2013

url重写规则

IIS6

<RewriterConfig>
   <Rules>
       
      无参数一级页面
     <RewriterRule>
       <LookFor>~/([\0-9a-zA-Z]+)-([\d]+)/([\w-]+)\.html</LookFor>
       <SendTo><![CDATA[~/$1.aspx?classid=$2&ke=$3]]></SendTo>
     </RewriterRule>
     <RewriterRule>
       <LookFor>~/([0-9a-zA-Z]+)\.html</LookFor>
       <SendTo><![CDATA[~/$1.aspx]]></SendTo>
     </RewriterRule>     
     <RewriterRule>
       <LookFor>~/about-(\d{1,6})\.html</LookFor>
       <SendTo>~/about.aspx?id=$1</SendTo>
     </RewriterRule>
     <RewriterRule>
       <LookFor>~/about8.html</LookFor>
       <SendTo>~/about8.aspx</SendTo>
     </RewriterRule>
     <RewriterRule>
       <LookFor>~/newsbig-(\d{1,6})\.html</LookFor>
       <SendTo>~/newsbig.aspx?id=$1</SendTo>
     </RewriterRule>
     <RewriterRule>
       <LookFor>~/news-(.*)\.html</LookFor>
       <SendTo>~/news.aspx?ke=$1</SendTo>
     </RewriterRule>
     <RewriterRule>
       <LookFor>~/pro-(.*)\.html</LookFor>
       <SendTo>
         <![CDATA[~/pro.aspx?classid=$1]]>
     </SendTo>
     </RewriterRule>
     <RewriterRule>
       <LookFor>~/pro2-(.*)\.html</LookFor>
       <SendTo>~/pro2.aspx?ke=$1</SendTo>
     </RewriterRule>
     <RewriterRule>
       <LookFor>~/prob-(.*)-(.*)\.html</LookFor>
       <SendTo>
         <![CDATA[~/prob.aspx?id=$1&name=$2]]>
     </SendTo>
     </RewriterRule>
     <RewriterRule>
       <LookFor>~/probig-(\d{1,6})-(.*)\.html</LookFor>
       <SendTo>~/probig.aspx?id=$1</SendTo>
       <SendTo> <![CDATA[~/probig.aspx?id=$1&columnid=$2]]></SendTo>
     </RewriterRule>
     <RewriterRule>
       <LookFor>~/viewnews-(\d{1,6})\.html</LookFor>
       <SendTo>~/viewnews.aspx?id=$1</SendTo>
     </RewriterRule>
     <RewriterRule>
       <LookFor>~/products-(\d{1,6})\.html</LookFor>
       <SendTo>~/products.aspx?pid=$1</SendTo>
     </RewriterRule>
     <RewriterRule>
       <LookFor>~/products-(\d{1,6})\.html</LookFor>
       <SendTo>~/products.aspx?page=$1</SendTo>
     </RewriterRule>
     <RewriterRule>
       <LookFor>~/products-(\d{1,6})-(\d{1,6})\.html</LookFor>
       <SendTo><![CDATA[~/products.aspx?pid=$1&page=$2]]></SendTo>
     </RewriterRule>
     <RewriterRule>
       <LookFor>~/job-(\d{1,6})\.html</LookFor>
       <SendTo>~/job.aspx?page=$1</SendTo>
     </RewriterRule>

    
     <RewriterRule>
       <LookFor>~/yingping-(\d{1,6})\.html</LookFor>
       <SendTo>~/yingping.aspx?jid=$1</SendTo>
     </RewriterRule>

     <RewriterRule>
       <LookFor>~/viewproduct-(\d{1,6})-([\w-]+)\.html</LookFor>
       <SendTo>~/viewproduct.aspx?id=$1</SendTo>
     </RewriterRule>

      英文版
     <RewriterRule>
       <LookFor>~/en/([0-9a-zA-Z]+)\.html</LookFor>
       <SendTo><![CDATA[~/en/$1.aspx]]></SendTo>
     </RewriterRule>

     <RewriterRule>
       <LookFor>~/en/news-(\d{1,6})\.html</LookFor>
       <SendTo>~/en/news.aspx?page=$1</SendTo>
     </RewriterRule>

     <RewriterRule>
       <LookFor>~/en/viewnews-(\d{1,6})\.html</LookFor>
       <SendTo>~/en/viewnews.aspx?id=$1</SendTo>
     </RewriterRule>

     <RewriterRule>
       <LookFor>~/en/products-(\d{1,6})\.html</LookFor>
       <SendTo>~/en/products.aspx?pid=$1</SendTo>
     </RewriterRule>

     <RewriterRule>
       <LookFor>~/en/products-(\d{1,6})\.html</LookFor>
       <SendTo>~/en/products.aspx?page=$1</SendTo>
     </RewriterRule>

     <RewriterRule>
       <LookFor>~/en/products-(\d{1,6})-(\d{1,6})\.html</LookFor>
       <SendTo><![CDATA[~/en/products.aspx?pid=$1&page=$2]]></SendTo>
     </RewriterRule>

     <RewriterRule>
       <LookFor>~/en/job-(\d{1,6})\.html</LookFor>
       <SendTo>~/en/job.aspx?page=$1</SendTo>
     </RewriterRule>

     <RewriterRule>
       <LookFor>~/en/yingping-(\d{1,6})\.html</LookFor>
       <SendTo>~/en/yingping.aspx?jid=$1</SendTo>
     </RewriterRule>

     <RewriterRule>
       <LookFor>~/en/viewproduct-(\d{1,6})\.html</LookFor>
       <SendTo>~/en/viewproduct.aspx?id=$1</SendTo>
     </RewriterRule>

   </Rules>
 </RewriterConfig>
IIS7 (注意顺序)

<?xml version=”1.0″ encoding=”UTF-8″?>
<configuration>
   <system.webServer>
       <rewrite>
           <rules>
               <clear />
               <rule name=”LowerCaseRule1″ stopProcessing=”true”>
                   <match url=”[A-Z]” ignoreCase=”false” />
                   <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
                   <action type=”Redirect” url=”{ToLower:{URL}}” />
               </rule>
               <rule name=”asp” enabled=”false” patternSyntax=”ECMAScript” stopProcessing=”true”>
                   <match url=”.*.(?:asp|aspx|php|jsp|cgi|ini|mdb|config|bak)” negate=”false” />
                   <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
                   <action type=”Rewrite” url=”/err.asp” />
               </rule>
               <rule name=”html3″ patternSyntax=”ECMAScript” stopProcessing=”true”>
                   <match url=”^([0-9,a-z,/]+)_([0-9,a-z]+)_([0-9]+)_([0-9]+)\.html$” />
                   <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
                   <action type=”Rewrite” url=”{R:1}.asp?game={R:2}&amp;typeid={R:3}&amp;id={R:4}” />
               </rule>
               <rule name=”html2″ patternSyntax=”ECMAScript” stopProcessing=”true”>
                   <match url=”^([0-9,a-z,/]+)_([0-9,a-z]+)_([0-9]+)\.html$” />
                   <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
                   <action type=”Rewrite” url=”{R:1}.asp?game={R:2}&amp;typeid={R:3}” />
               </rule>
               <rule name=”html1″ patternSyntax=”ECMAScript” stopProcessing=”true”>
                   <match url=”^([0-9,a-z,/]+)_([0-9,a-z]+)\.html$” negate=”false” />
                   <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
                   <action type=”Rewrite” url=”{R:1}.asp?game={R:2}” />
               </rule>
               <rule name=”html0″ patternSyntax=”ECMAScript” stopProcessing=”true”>
                   <match url=”^([0-9,a-z,/]+)\.html$” ignoreCase=”true” />
                   <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
                   <action type=”Rewrite” url=”{R:1}.asp” />
               </rule>
           </rules>
       </rewrite>
       <defaultDocument>
           <files>
               <add value=”index.asp” />
           </files>
       </defaultDocument>
       <httpErrors>
           <error statusCode=”500″ subStatusCode=”100″ path=”/500-100.asp” responseMode=”ExecuteURL” />
       </httpErrors>
   </system.webServer>
   <location path=”mh”>
   </location>
</configuration>
IIS7 重写IIS6的 (注意顺序)有的地方需调整

<rewrite>
     <rules>
       <clear />
   <rule name=”html1″ patternSyntax=”ECMAScript” stopProcessing=”true”>
     <match url=”^([\0-9a-zA-Z]+)-([\d]+)/([\w-]+)\.htm” />
     <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
     <action type=”Rewrite” url=”{R:1}.aspx?classid={R:2}&amp;ke={R:3}” />
   </rule>

   <rule name=”html3″ patternSyntax=”ECMAScript” stopProcessing=”true”>
     <match url=”^about-(\d{1,6})\.html$” ignoreCase=”true” />
     <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
     <action type=”Rewrite” url=”about.aspx?id={R:1}” />
   </rule>
  <!– <rule name=”html4″ patternSyntax=”ECMAScript” stopProcessing=”true”>
     <match url=”about.html” ignoreCase=”true” />
     <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
     <action type=”Rewrite” url=”about.aspx” />
   </rule>–>
   <rule name=”html5″ patternSyntax=”ECMAScript” stopProcessing=”true”>
     <match url=”^newsbig-(\d{1,6})\.html” ignoreCase=”true” />
     <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
     <action type=”Rewrite” url=”newsbig.aspx?id={R:1}” />
   </rule>
   <rule name=”html6″ patternSyntax=”ECMAScript” stopProcessing=”true”>
     <match url=”^news-(.*)\.html” ignoreCase=”true” />
     <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
     <action type=”Rewrite” url=”news.aspx?classid={R:1}” />
   </rule>  

   <rule name=”html7″ patternSyntax=”ECMAScript” stopProcessing=”true”>
     <match url=”^pro-(.*)\.html$” ignoreCase=”true” />
     <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
     <action type=”Rewrite” url=”pro.aspx?classid={R:1}” />
   </rule>
   <rule name=”html8″ patternSyntax=”ECMAScript” stopProcessing=”true”>
     <match url=”^pro2-(.*)\.html” ignoreCase=”true” />
     <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
     <action type=”Rewrite” url=”pro2.aspx?ke={R:1}” />
   </rule>
   <rule name=”html9″ patternSyntax=”ECMAScript” stopProcessing=”true”>
     <match url=”^prob-(.*)-(.*)\.html” ignoreCase=”true” />
     <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
     <action type=”Rewrite” url=”prob.aspx?id={R:1}&amp;name={R:2}” />
   </rule>
   <rule name=”html10″ patternSyntax=”ECMAScript” stopProcessing=”true”>
     <match url=”^probig-(\d{1,6})-(.*)\.html” ignoreCase=”true” />
     <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
     <action type=”Rewrite” url=”probig.aspx?id={R:1}&amp;columnid={R:2}” />
   </rule>
   <rule name=”html11″ patternSyntax=”ECMAScript” stopProcessing=”true”>
     <match url=”^viewnews-(\d{1,6})\.html” ignoreCase=”true” />
     <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
     <action type=”Rewrite” url=”viewnews.aspx?id={R:1}” />
   </rule>
   <rule name=”html12″ patternSyntax=”ECMAScript” stopProcessing=”true”>
     <match url=”^products-(\d{1,6})\.html” ignoreCase=”true” />
     <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
     <action type=”Rewrite” url=”products.aspx?pid={R:1}” />
   </rule>
   <rule name=”html13″ patternSyntax=”ECMAScript” stopProcessing=”true”>
     <match url=”^products-(\d{1,6})\.html” ignoreCase=”true” />
     <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
     <action type=”Rewrite” url=”products.aspx?page={R:1}” />
   </rule>
   <rule name=”html14″ patternSyntax=”ECMAScript” stopProcessing=”true”>
     <match url=”^products-(\d{1,6})-(\d{1,6})\.html” ignoreCase=”true” />
     <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
     <action type=”Rewrite” url=”pproducts.aspx?pid={R:1}&amp;page={R:2}” />
   </rule>
   <rule name=”html15″ patternSyntax=”ECMAScript” stopProcessing=”true”>
     <match url=”^job-(\d{1,6})\.html” ignoreCase=”true” />
     <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
     <action type=”Rewrite” url=”job.aspx?page={R:1}” />
   </rule>
   <rule name=”html16″ patternSyntax=”ECMAScript” stopProcessing=”true”>
     <match url=”^yingping-(\d{1,6})\.html” ignoreCase=”true” />
     <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
     <action type=”Rewrite” url=”yingping.aspx?jid={R:1}” />
   </rule>
   <rule name=”html17″ patternSyntax=”ECMAScript” stopProcessing=”true”>
     <match url=”^viewproduct-(\d{1,6})-([\w-]+)\.html” ignoreCase=”true” />
     <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
     <action type=”Rewrite” url=”viewproduct.aspx?id={R:1}” />
   </rule>
<!–<rule name=”html18″ patternSyntax=”ECMAScript” stopProcessing=”true”>
     <match url=”about\.html” ignoreCase=”true” />
     <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
     <action type=”Rewrite” url=”about.aspx” />
   </rule>–>
<rule name=”html19″ patternSyntax=”ECMAScript” stopProcessing=”true”>
     <match url=”^probig-(\d{1,6})\.html$” ignoreCase=”true” />
     <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
     <action type=”Rewrite” url=”probig.aspx?id={R:1}” />
   </rule>
 <rule name=”html20″ patternSyntax=”ECMAScript” stopProcessing=”true”>
     <match url=”^pro.html?classid=(.*)$” ignoreCase=”true” />
     <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
     <action type=”Rewrite” url=”pro.aspx?classid={R:1}” />
   </rule>
  
  <rule name=”html22″ patternSyntax=”ECMAScript” stopProcessing=”true”>
     <match url=”^([0-9a-zA-Z]+)\.html” negate=”false” />
     <conditions logicalGrouping=”MatchAll” trackAllCaptures=”false” />
     <action type=”Rewrite” url=”{R:1}.aspx” />
   </rule>
     </rules>
   </rewrite>

 

来自:http://blog.sina.com.cn/s/blog_79a08b290100x6a1.html