关于在Webconfig中定义301重定向时正则表达式如何写

weixin_44336905 2019-01-04 10:39:44
我原来是在web.config中定义了每一个网址的重定向去向,但是超过了1000左右重定向就出现错误了,但是我要重定向的页面有3000多个,但是这些文件目录下只有部分文件需要重定向,因此不能用目录重定向的方式。我原来的方法如下:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="17276" stopProcessing="true">
<match url="^cs_17276.html" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="https://www.xxx.com/xxx/h/17276.html" redirectType="Permanent"/>
</rule>
<rule name="17271" stopProcessing="true">
<match url="^cs_17271.html" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
<action type="Redirect" url="https://math.xxx.com/xxx/h/17271.html" redirectType="Permanent"/>
</rule>
...
</rules>
</rewrite>
</system.webServer>
</configuration>

我需要实现一个目录下某些文件定向到相应的网站去,在webconfig里的一个rule中如何用正则表达式来写呢?
如:
1、cs_17276.html、cs_17286.html、cs_17476.html...。分别定向到:https://www.xxx.com/xxx/h/17276.html、https://www.xxx.com/xxx/h/17286.html、https://www.xxx.com/xxx/h/17476.html
2、cs_17273.html、cs_17282.html、cs_17471.html...。分别定向到:https://www.xxx.com/xxx/w/17273.html、https://www.xxx.com/xxx/w/17282.html、https://www.xxx.com/xxx/w/17471.html
...全文
447 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
游北亮 2019-01-10
  • 打赏
  • 举报
回复
这种东西,为什么不写到数据库里? 根据url读取数据库,进行301重定向 还方便维护,修改配置也不需要发布代码。
Hello World, 2019-01-10
  • 打赏
  • 举报
回复
重定向到某个页面,并将来源页面的某些参数传过来,根据参数再转发;
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>

<rule name="Index" stopProcessing="true">
<match url="^index.html" />
<action type="Rewrite" url="index.php" />
</rule>

<rule name="Rule1" stopProcessing="true">
<match url="^news_([0-9]+).html" />
<action type="Rewrite" url="news.php?nid={R:1}" />
</rule>

<rule name="Rule2" stopProcessing="true">
<match url="news_list_([0-9]+)_([0-9]+).html" />
<action type="Rewrite" url="news_list.php?nid={R:1}&page={R:2}" />
</rule>

</rules>
</rewrite>
</system.webServer>
</configuration>
weixin_44336905 2019-01-04
  • 打赏
  • 举报
回复
就没有人能够解决这个问题吗?

62,244

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧