asp.net-mvc - IIS Url 使用正则表达式重写重定向到错误的目标
问题描述
我必须使用正则表达式进行重定向...
我必须执行以下重定向:
www.mysite.com/old-category/old-subcategory -> www.mysite.com/new-category/new-subcategory
www.mysite.com/old-category/old-subcategory/old-page1 -> www.mysite.com/new-category/new-subcategory/new-page1
www.mysite.com/old-category/old-subcategory/old-page2 -> www.mysite.com/new-category/new-subcategory/new-page2
...
www.mysite.com/old-category/old-subcategory/old-pageN -> www.mysite.com/new-category/new-subcategory/new-pageN
哪里new-pageN
可以是一个随机词...
这是我在 web.config 中的规则:
<rewrite>
<rules>
...
<rule name="myCustomRule">
<match url="^old-category/old-subcategory/(.*)" ignoreCase="false" />
<action type="Redirect" url="new-category/new-subcategory/{R:1}" />
</rule>
</rules>
</rewrite>
问题是当我www.mysite.com/old-category/old-subcategory/old-page1
在浏览器中写入时,它被重定向到www.mysite.com/new-category/new-subcategory/n
. 它只需要旧网址最后一段的第一个字母。
我不明白出了什么问题……对我来说一切看起来都是正确的……我也尝试过
^old-category/old-subcategory/(.+)
^old-category/old-subcategory/(\w+)
^old-category/old-subcategory/([0-9a-zA-Z_]+)
^old-category/old-subcategory/(\b\w+\b)
没有任何效果...怎么了?
谢谢
解决方案
你的问题不太清楚......顺便说一句
尝试转义 "/"
<match url="^old-category\/old-subcategory\/(.*)"
ignoreCase="false" />我认为重定向应该是:
<action type="Redirect" url="/new-category/new-subcategory/{R:1}" />
或者
<action type="Redirect" url="http://www.example.com/new-category/new-subcategory/{R:1}" />
推荐阅读
- android - 当应用程序被锁定而不是在后台时,我如何检测设备电源按钮按下
- vue.js - NuxtJS - 网络包。如何拆分供应商和应用程序以分离 css 块?
- android - 使用 GSON 时,是否必须为需要排除的 JSON 对象提供类?
- c++ - 将位图转换为 PIX
- android - 使用 ModelClass 在具有现有数据的子项下添加新数据
- security - Secureboot:grub 可以加载,但是 bzImage 有一个“无效签名”
- database - 如何减少对 .NET Core 布局的查询
- python - 正确使用类中字典的 getter/setter —— 防止在设置字典元素时调用 getter
- c# - 试图在没有多维数组的情况下解决背包问题
- javascript - 如何将 JSON 对象附加到 react.js 中 JS 文件中的现有 JSON 对象