Search code examples
asp.netasp.net-mvc-3iisurl-rewritingasp.net-mvc-routing

Setting up URL Rewrite rule for a specific domain SEO


On Google there is the following Url

www.domain.ch/House/rent

So now my page is now available in multi language and i have now the language in the url, and it looks like this

www.domain.ch/en/house/rent

So I will redirect all old links with url rewrite in the web.config, but I can't find out the match condition to find out if there is a languege insite the url.

My role:

<rule name="mydomain.com" >
  <match url="(.*)" />
  <conditions logicalGrouping="MatchAll">
    <add input="{HTTP_HOST}" pattern="^(localhost:3005/|localhost:3005/)$" />
  </conditions>
 <action type="Redirect" url="http://localhost:3005/de/{R:1}" logRewrittenUrl="true" />
</rule>

Thanks for any help!


Solution

  • <rule name="mydomain.com" stopProcessing="true" >
      <match url="(.*)" />
      <conditions>
        <!-- redirect only if the URL doesn't contain /en/ or /de/ already (negate = true)-->
        <add input="{URL}" pattern="/en/|/de/" negate="true" />
      </conditions>
      <action type="Redirect" url="de/{R:1}"  />
    </rule>