IIS URL重写规则以替换部分URL [英] IIS URL Rewrite rule to replace part of the URL

查看:96
本文介绍了IIS URL重写规则以替换部分URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是IIS Rewrite规则的新手,并试图创建一个规则来替换部分url

I am new to the IIS Rewrite rule and trying to create a rule to replace part of url

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

e.g.www.abc.com/assets/global/xyz.jpg

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

should redirect to www.abc.com**/en/globalassets/**assets/global/xyz.jpg

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

I fiddle around with the following rule but no success

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

推荐答案

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

According to your description, I have tested on my side , you could use urlrewite rule as below:

<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之类的值,因为这部分只能捕获网址的路径.

Firstly, we couldn't add value like **.com in match url, because this part could only catch path of the url.

您可能会看到这是一个网址结构:

You could see this is a url structure:

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

您只能在conditions标签中获得它,而不能在pattern中获得它.

You could only get it in conditions tag but not pattern.

然后,您应该添加条件以检查请求URL是否匹配"en/globalassets",或者避免避免一次又一次地执行重定向规则.

Then you should add condition to check the request URL match "en/globalassets" or not to avoid running redirect rule once and once again.

这篇关于IIS URL重写规则以替换部分URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆