繁体   English   中英

IIS URL重写规则以替换部分URL

[英]IIS URL Rewrite rule to replace part of the URL

我是IIS Rewrite规则的新手,正在尝试创建规则来替换部分url

例如www.abc.com/assets/global/xyz.jpg

应该重定向到www.abc.com ** / en / globalassets / ** assets / global / xyz.jpg

我在遵循以下规则,但没有成功

<rule name="url replace">
<match url="^(.com/assets/global/)" />
<action type="Rewrite" url=".com/en/globalassets/assets/global/{R:2}" />
</rule>

根据您的描述,我已经进行了测试,可以使用urlrewite规则,如下所示:

<rule name="rule1" enabled="true" stopProcessing="true">
                    <match url="assets/global/(.*)" />
                    <conditions>
                        <add input="{REQUEST_URI}" pattern="en/globalassets" negate="true" />
                    </conditions>
                    <action type="Redirect" url="http://{domain}/en/globalassets/assets/global/{R:1}" />
                </rule>

首先,我们无法在匹配网址中添加**。com之类的值,因为这部分只能捕获网址的路径。

您可以看到这是一个url结构:

http(s)://httphost/path?querystring.

您只能在条件标签中获得它,而不能在模式中获得它。

然后,您应该添加条件以检查请求URL匹配“ en / globalassets”,还是不避免一次又一次运行重定向规则。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM