Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 使用正则表达式重写IIS Url重定向到错误的目标_Asp.net Mvc_Redirect_Iis_Url Rewriting_Web Config - Fatal编程技术网

Asp.net mvc 使用正则表达式重写IIS Url重定向到错误的目标

Asp.net mvc 使用正则表达式重写IIS Url重定向到错误的目标,asp.net-mvc,redirect,iis,url-rewriting,web-config,Asp.net Mvc,Redirect,Iis,Url Rewriting,Web Config,我必须使用正则表达式执行重定向 我必须执行以下重定向: 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.

我必须使用正则表达式执行重定向

我必须执行以下重定向:

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
可以是randow单词

下面是我在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>
什么都不管用。。。怎么了


谢谢你

你的问题不太清楚。。。 顺便说一下

  • 尝试转义“/”

  • 我认为重定向应该是:

    <action type="Redirect" url="/new-category/new-subcategory/{R:1}" />
    
    
    

    
    
  • 这条规则在我的测试中有效。为了便于观察重写过程,我将重定向改为重写,但两者的结果相同。请按照lexli的文档签入失败请求跟踪。不要忘记将重定向更改为“重写”,这样可以记录整个重写过程。
    <action type="Redirect" url="/new-category/new-subcategory/{R:1}" />
    
    <action type="Redirect" url="http://www.example.com/new-category/new-subcategory/{R:1}" />