0

I was trying to make a URL rewrite rule in the web.config. The rule should be done to create a fake url of a page.

If i have this link:

wwww.mywebsite.com/en-us/mypage it should redirect to wwww.mywebsite.com/en-us/fakepage

but in certain cases it could be that the webpage is

wwww.mywebsite.com/en-us/mypage/value to wwww.mywebsite.com/en-us/fakepage/value.

O have created something similar to this but it is not working correctly.

    <rewrite>
    <rules>
      <rule name="Rewrite rule" stopProcessing="true">
        <match url="(.*)en-us/mypage" />
        <action type="Rewrite" url="en-us/fakepage" appendQueryString="false" redirectType="Permanent"/>
      </rule>
      <rule name="Rewrite2" stopProcessing="true">
        <match url="(.*)en-us/mypage$" />
        <action type="Redirect" url="en-us/fakepage" appendQueryString="false" redirectType="Permanent"/>
      </rule>
    </rules>
  </rewrite>
cheesemacfly
  • 11,622
  • 11
  • 53
  • 72
comb
  • 463
  • 1
  • 4
  • 13

1 Answers1

0

You need to create a grouping in your <match> tag and backreference it using {R:}:

<rules>
  <rule name="Rewrite rule" stopProcessing="true">
    <match url="(.*)en-us/mypage(.*)$" />
    <action type="Rewrite" url="en-us/fakepage{R:2}" appendQueryString="false" redirectType="Permanent"/>
  </rule>
</rules>
Jon Lin
  • 142,182
  • 29
  • 220
  • 220