需求:将 www.abc.com/e/tags?tagsid=1 改写成 www.abc.com/softlink/1.html形式;
环境:Windows服务器;
路径:D:/web/www.abc.com/wwwroot/www/web.config;
位置:在web.config的rewrite标签中,添加rules,如最后一条(第20-23行);
释义:
a.<match url="^softlink/([0-9]+)\.html$" ignoreCase="false" />是要转成的链接样式;
b.<action type="Rewrite" url="/e/tags/?tagid={R:1}" appendQueryString="false" />是原来链接样式;
c.{R:1}表示第一个变量,若跟多个变量,可写为{R:2},变量之间以原符号的转义字符形式相连(如第9行)。
1 <rewrite> 2 <rules> 3 <rule name="已导入的规则 1"> 4 <match url="^(soft|android|ios|jiaocheng)/greenxiazai-([0-9]+)-([0-9]+)?(-hot|-size|-best)?\.html$" ignoreCase="false" /> 5 <action type="Rewrite" url="/e/action/relist.php?pd={R:1}&classid={R:2}&p={R:3}&orderby={R:4}" appendQueryString="false" /> 6 </rule> 7 <rule name="已导入的规则 2"> 8 <match url="^tags/([0-9]+)-([0-9]+)\.html$" ignoreCase="false" /> 9 <action type="Rewrite" url="/e/tags/index.php?tagid={R:1}&page={R:2}" appendQueryString="false" /> 10 </rule> 11 <rule name="已导入的规则 3"> 12 <match url="^sitemap\.xml$" ignoreCase="false" /> 13 <action type="Rewrite" url="/sitemap.php" /> 14 </rule> 15 <rule name="已导入的规则 4"> 16 <match url="^sitemap_data_([0-9]+)\.xml$" ignoreCase="false" /> 17 <action type="Rewrite" url="/sitemap.php?classid={R:1}" appendQueryString="false" /> 18 </rule> 19 <!-- tags热标签伪静态 --> 20 <rule name="已导入的规则 5"> 21 <match url="^softlink/([0-9]+)\.html$" ignoreCase="false" /> 22 <action type="Rewrite" url="/e/tags/?tagid={R:1}" appendQueryString="false" /> 23 </rule> 24 </rules> 25 </rewrite>