IIS URL Rewrite rule to replace part of the URL

你说的曾经没有我的故事 提交于 2021-01-29 05:15:06

问题


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

e.g.www.abc.com/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>

回答1:


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>

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.

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

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



来源:https://stackoverflow.com/questions/55456611/iis-url-rewrite-rule-to-replace-part-of-the-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!