I want to redirect some pages from an old website (oldsite.com) to a new website (newsite.*) according to the following rules:
For this I've created the following rules (for sv in this case):
<rule name="Redirect /sv to .se" stopProcessing="true">
<match url="^sv/?$" />
<action type="Redirect" url="http://newsite.se" />
</rule>
<rule name="Redirect /sv/* except some pages" stopProcessing="true">
<match url="^sv/.+" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_URI}" pattern="^sv/page1(.*)" negate="true" />
<add input="{REQUEST_URI}" pattern="^sv/page2(.*)" negate="true" />
</conditions>
<action type="Redirect" url="http://newsite.se" />
</rule>
The first rule works fine but not the second. The problem is that my negated conditions don't seem to work. When I enter oldsite.com/sv/page1 I still get redirected to newsite.se. Maybe I've misunderstood how negated conditions work, but shouldn't the second rule execute the action if and only if both conditions are true (evaluate to false), i.e. the REQUEST_URI doesn't match /page1 and /page2?
You understand the concept very well.
The only problem is that the {REQUEST_URI}
always start with a /
, and the url never matches with a pattern like ^sv/page1(.*)
, finally you have a brand new false positive.
So, you need to include leading slashes in the pattern.
<add input="{REQUEST_URI}" pattern="^/sv/page1(.*)" negate="true" />
<add input="{REQUEST_URI}" pattern="^/sv/page2(.*)" negate="true" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With