带参数url重写规则之.htaccess和web.config的写法
    
  
      
      
     
    
      
        要求:把链接http://demo.com/list-2.html?cid=2&q=深圳 解析到http://demo.com/Topic/tlist?cid=2&q=深圳适用场景:在网站用重写规则中某些链接和 form 表单的 get 提交时会用到。
1 2 3 4
   | RewriteCond %{QUERY_STRING} ^cid=(\d+)&q=(.*)$ RewriteRule list-(\d+)\.html$     Topic/tlist\?cid=$1&q=%2 RewriteCond %{QUERY_STRING} ^$ RewriteRule list-(\d+)\.html$     Topic/tlist\?cid=$1
  | 
 
1 2 3 4 5 6 7 8
   | <rule name="带参数的url重写规则" >     <match url="list-(\d+)\.html" />     <conditions trackAllCaptures="true">         <add input="{QUERY_STRING}" pattern="&?(cid=[^&]+)&?" />         <add input="{QUERY_STRING}" pattern="&?(q=[^&]+)&?" />     </conditions>     <action type="Redirect" url="Topic/tlist?cid={R:1}&{C:1}&{C:2}" appendQueryString="false" /> </rule>
   | 
 
备:(action 里的 type 中"Redirect"为跳转,"Rewrite"为重写)
      
     
    
      
  
  
    
      
      
        
        致力于网站建设与Web开发。喜欢新事物,关注前后端动态,对新的技术有追求, 做一个优秀的web全栈工程师。