问题
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