![](/img/trans.png)
[英]ASP.NET rewrite redirect url on IIS (for Facebook social login)
[英]regex to replace one word in url - 301 Redirect using URL Rewrite IIS asp.net
我想設置一個301重定向
mysite.com/banana mysite.com/fruit
mysite.com/banana/yellow mysite.com/fruit/yellow
mysite.com/banana/yellow/sale mysite.com/fruit/yellow/sale
(“黃色”和“銷售”這兩個詞可以用任何東西代替,它們是路線中的變量。)
這適用於第一種情況,但不適用於其他情況:
<rule name="banana" stopProcessing="true">
<match url="banana" />
<action type="Redirect" url="fruit" />
</rule>
基於這個問題: 使用iis的url重寫模塊用dash替換下划線
這僅適用於第三種情況:
<rule name="banana" stopProcessing="true">
<match url="(mysite.com.*/[^/]*?)banana/([^/_]*)/([^/_]*)$" />
<action type="Redirect" url="{R:1}fruit/{R:2}/{R:3}" />
</rule>
我需要的是返回的正則表達式
{R:1} mysite.com/
{R:2} /黃色/銷售
要么
{R:1} mysite.com/
{R:2}
為什么不保持簡單?
<match url="mysite.com/banana(/.+)*$" />
<action type="Redirect" url="mysite.com/fruit{R:1}" />
或者如果你只想深入兩個層次:
<match url="mysite.com/banana((?:/[^/]+){0,2})$" />
<action type="Redirect" url="mysite.com/fruit{R:1}" />
以下內容如何:
<rule name="banana" stopProcessing="true">
<match url="mysite.com/banana(.+)?" />
<action type="Redirect" url="mysite.com/fruit{R:1}" />
</rule>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.