IIS replace part of url

自作多情 提交于 2021-01-28 19:16:47

问题


I'm trying to replace "se" with "sv" in a url by using url rewrite in iis.

Url look like this: www.somedomain.com/se/baadmarked/baade

And should look like this: www.somedomain.com/sv/baadmarked/baade

My current rule look like this:

<rule name="se to sv" patternSyntax="ECMAScript" stopProcessing="true">
    <match url="(.*)" />
    <action type="Redirect" url="{C:1}sv{C:3}" appendQueryString="false" />
    <conditions logicalGrouping="MatchAny">
        <add input="{HTTP_HOST}{QUERY_STRING}" pattern="(.*)(se)(.*)" />
    </conditions>
</rule>

I've tried a lot, but nothing gets the job done.


回答1:


It sounds like you want to use the Rewrite feature and not the Redirect feature.

The rule should look like this:

<rule name="se to sv">
    <match url="^(.*)/se/(.*)" />
    <action type="Rewrite" url="{R:1}/sv/{R:2}" />
</rule>

The match is breaking the rule into two parts. The first part is the domains and the second part is everything after the se.

The action is saying to rewrite all of these address to {R:1} The domain part, /sv/ then {R:2} everything after the se.

If you did want Redirect just change the action from Rewrite to Redirect. It's not very clear.

You can still add stopProcessing="true" and appendQueryString="false" if you need.



来源:https://stackoverflow.com/questions/39368393/iis-replace-part-of-url

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